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

Discussion in 'Python' started by Karthik, Sep 5, 2007.

  1. Karthik

    Karthik Guest

    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()
    Karthik, Sep 5, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roderik

    filtering wave file (real-time)

    Roderik, Jul 1, 2004, in forum: Java
    Replies:
    3
    Views:
    335
    Andrew Thompson
    Jul 4, 2004
  2. John
    Replies:
    0
    Views:
    1,169
  3. jmdeschamps

    tkSnack or other sound tool

    jmdeschamps, Feb 11, 2004, in forum: Python
    Replies:
    1
    Views:
    392
    Russell E. Owen
    Feb 11, 2004
  4. Replies:
    0
    Views:
    446
  5. red floyd
    Replies:
    5
    Views:
    1,031
    Nathan Wijnia
    Jun 21, 2007
Loading...

Share This Page