Я думаю, что это очень вероятно, что я просто глуп, но я пытаюсь создать пользовательский класс, который имеет пользовательские функции обратного вызова для использования с 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() принимает ровно один аргумент (5 дается)
Любые идеи?