【发布时间】:2014-12-11 14:56:50
【问题描述】:
代码有什么问题?
from pyaudio import *
class sphinx():
def __init__(self, samprate=16000):
self.recorder(samprate)
def recorder(self, samprate):
audio = PyAudio()
recorder = audio.open(rate=samprate, channels=1, format=paInt16, input=True, frames_per_buffer=1024)
return recorder
def start(self):
in_speech_bf = True
self.recorder.start_stream()
...
decoder = sphinx()
decoder.start()
Python 返回:
Traceback (most recent call last):
File "decoder.py", line 58, in <module>
decoder.start()
File "decoder.py", line 28, in start
self.recorder.start_stream()
AttributeError: 'function' object has no attribute 'start_stream'
当我不使用类和方法时,PyAudio 可以正常工作。
提前致谢。
【问题讨论】:
标签: python class methods attributes initialization