How do i record and invert a sound wave in real time using Tkinter,tkSnack and wave modules?

K

Karthik

Hi,
I want to record a sound wave from a mic and at the same time invert
it and play the inverted wave.My code goes as follows, however nothing
is written into the E:\inverted.wav file.Thanks in advance for any
help.

from Tkinter import *
root = Tk()
import tkSnack
tkSnack.initializeSnack(root)
t=tkSnack
import wave
import audioop
a=audioop
w=wave
import threading
import os
def fin():

s=t.Sound(file='E:/final.wav')
s.frequency=44100
s.record() #Start recording
def invert():
global f,i,as
f=w.open("E:\\final.wav","r")
frame=f.readframes(1)
i=w.open("E:\\inverted.wav","w")
#sw=f.getsampwidth()
i.setsampwidth(2)
#nf=f.getnframes()
i.setnframes(30*50000)
#nc=f.getnchannels()
i.setnchannels(1)
#fr=f.getframerate()
i.setframerate(44100)
f.setpos(220500)
c=0
while frame:
#invert and write it to inverted.wav
i.writeframesraw(audioop.mul(frame,2,-1.0))
c=c+1
frame=f.readframes(1)
if c==100:
as=t.Sound(load='E:/inverted.wav')
as.play()


def stp():
s.stop()
as.stop()
f.close()
i.close()

k=threading.Timer(30.0000,stp) #Stop recording after 30 sec
k.start()
j=threading.Timer(5.00000,invert) #Start reading recorded file
j.start() #after 5sec

fin()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top