2015-09-21 32 views
0

我認爲這很可能只是我愚蠢,但我試圖創建一個用戶定義的類,它具有用戶定義的回調函數與pyaudio一起使用。下面是我有:在用戶定義的類中使用Pyaudio回調方法

class asoa_io:   
    def write_callback(self): 
    def _write_callback(in_data, frame_count, time_info, status): 
     data = self.template_wave[template_idx*template_framesize:(template_idx+1)*template_framesize - 1] 
     self.template_idx += 1 
     return (data, pyaudio.paContinue) 
    return _write_callback 

    def read_callback(self): 
    def _read_callback(in_data, frame_count, time_info, status): 
     self.signal += in_data # This has the incoming signal as a list of frames. 
     return (in_data, pyaudio.paContinue) 
    return _read_callback 

    """ Synthesize the speech and do any preprocessing. 
    Note that we want to use the kal_diphone voice for synthesis. 
    """ 
    def __init__(self, text_string): 
    temp_fd, template_file = tempfile.mkstemp() 
    string_file = tempfile.NamedTemporaryFile() 


    string_file.write(text_string) 
    string_file.flush() 


    if (subprocess.call([PATH_TO_TEXT2WAVE, string_file.name, "-o", template_file]) > 0): 
     print "Error running text2wave" 

    string_file.close() 


    self.template_rate, self.template_wave = scipy.io.wavfile.read(template_file) 
    self.template_length = len(self.template_wave) 

    self.pa = pyaudio.PyAudio() 
    self.input_stream = self.pa.open(format=pyaudio.paInt16, 
           channels=1, rate = self.template_rate, input=True, 
           stream_callback = self.read_callback) 
    self.output_stream = self.pa.open(format=pyaudio.paInt16, 
           channels=1, rate = self.template_rate, output=True, 
           stream_callback = self.write_callback) 

    self.template_idx = 0 
    self.signal = [] 


    def start_speech(self): 
    self.output_stream.start_stream() 
    self.input_stream.start_stream() 

調用函數部分不能正常工作,但 - 我得到的錯誤

write_callback()恰恰1個參數(5給出)

有沒有想法?

回答

0

好吧,看來我是對的,我只是愚蠢。

如果使read_callback具有5個變量的功能,則適用。

DEF read_callback(個體,IN_DATA,frame_count,time_info,狀態):

和類似地用write_callback

相關問題