下面的代碼我試圖在樹莓派3運行該模型B具有容量大了一點關於它的記憶,是我面臨的代碼的問題是,它有時運行:如何使用Pyaudio python模塊在沒有溢出的情況下捕獲Raspberry Pi中的音頻?
from os import environ, path
import pyaudio
from pocketsphinx.pocketsphinx import *
from sphinxbase.sphinxbase import *
MODELDIR = "../../../model"
DATADIR = "../../../test/data"
config = Decoder.default_config()
config.set_string('-hmm', path.join(MODELDIR, 'en-us/en-us'))
config.set_string('-lm', path.join(MODELDIR, '3199.lm'))
config.set_string('-dict', path.join(MODELDIR, '3199.dic'))
config.set_string('-logfn', '/dev/null')
decoder = Decoder(config)
p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=1024)
stream.start_stream()
in_speech_bf = False
decoder.start_utt()
while True:
buf = stream.read(1024)
if buf:
decoder.process_raw(buf, False, False)
if decoder.get_in_speech() != in_speech_bf:
in_speech_bf = decoder.get_in_speech()
if not in_speech_bf:
decoder.end_utt()
result = decoder.hyp().hypstr
print 'Result:', result
if result == 'yes':
print 'Do whatever you want'
decoder.start_utt()
else:
break
decoder.end_utt()
該程序不斷崩潰並拋出以下異常: OSError:[-9985] Errno設備不可用
您鏈接的代碼不會從麥克風讀取。您需要提供您實際使用的代碼和完整的日誌輸出,而不僅僅是錯誤。在RaspberryPI上使用pocketsphinx不可能使用語言模型進行大量的詞彙連續語音識別,但速度太慢。 –
對不起,我已更新問題帖子。 – 0x01Brain
如果你的音頻配置支持那麼你可以嘗試在44.1khz錄製。然後你需要添加選項'-samprate 44100 -nfft 2048'到解碼器配置。或者,您可以在系統上正確配置pulseaudio/alsa-dmix以爲您進行重採樣。 –