471,624 Members | 1,937 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,624 software developers and data experts.

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

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()

Sep 5 '07 #1
0 2026

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by jmdeschamps | last post: by
3 posts views Thread by Bill Dandreta | last post: by
1 post views Thread by Niklas Paro | last post: by
4 posts views Thread by Robert Gravereaux | last post: by
7 posts views Thread by Lee Moody | last post: by
4 posts views Thread by sittner | last post: by
reply views Thread by leo001 | last post: by
1 post views Thread by ZEDKYRIE | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.