录制时的Tkinter计时器

时间:2016-01-13 22:23:26

标签: python timer tkinter record pyaudio

与主题相同,我想在录制功能运行时创建计时器。我已经尝试了很多想法,但所有这些想法都是错误的,或者只是分手程序,也许你有一些想法?

class rec(object):  
  def __init__(self):
    FORMAT = pyaudio.paInt16
    CHANNELS = 2
    RATE = 44100
    CHUNK = 1024
    WAVE_OUTPUT_FILENAME = str(e2.get() + '.wav')       

    try:        
      RECORD_SECONDS = int(e1.get())
    except ValueError:
      tkMessageBox.showinfo("Error", "Please Enter number of seconds")

    i = 0
    while os.path.exists(WAVE_OUTPUT_FILENAME):     
      WAVE_OUTPUT_FILENAME = str(e2.get() + '%d.wav'%i)
      i += 1

    audio = pyaudio.PyAudio()
    stream = audio.open(format=FORMAT, channels=CHANNELS,
                        rate=RATE, input=True,
                        frames_per_buffer=CHUNK)

    frames = []

    print "recording...\n\n"
    for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
      sys.stdout.write('\r%i' % i)
      data = stream.read(CHUNK)
      frames.append(data)
    print "\nfinished recording\n"

    # stop Recording
    stream.stop_stream()
    stream.close()
    audio.terminate()

    waveFile = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
    waveFile.setnchannels(CHANNELS)
    waveFile.setsampwidth(audio.get_sample_size(FORMAT))
    waveFile.setframerate(RATE)
    waveFile.writeframes(b''.join(frames))

    # waveFile.Wave_read.getnframes()

    waveFile.close()
    tkMessageBox.showinfo("Recorded", "Track:%s"%WAVE_OUTPUT_FILENAME)

我尝试用计时器制作其他功能并启动该功能,当我按下按钮,但如果我按下按钮首先程序运行rec功能,并且在计时器功能消失后,我也尝试通过管道启动这些功能但它确实同样,我必须用线程做到吗?

0 个答案:

没有答案