我最近在python中使用口袋狮身人面像.我已经成功地通过以下示例来识别录制的wav.
#!/usr/bin/env python
import sys,os
def decodeSpeech(hmmd,lmdir,dictp,wavfile):
"""
Decodes a speech file
"""
try:
import pocketsphinx as ps
import sphinxbase
except:
print """Pocket sphinx and sphixbase is not installed
in your system. Please install it with package manager.
"""
speechRec = ps.Decoder(hmm = hmmd, lm = lmdir, dict = dictp)
wavFile = file(wavfile,'rb')
wavFile.seek(44)
speechRec.decode_raw(wavFile)
result = speechRec.get_hyp()
return result[0]
if __name__ == "__main__":
hmdir = "/home/jaganadhg/Desktop/Docs_New/kgisl/model/hmm/wsj1"
lmd = "/home/jaganadhg/Desktop/Docs_New/kgisl/model/lm/wsj/wlist5o.3e-7.vp.tg.lm.DMP"
dictd = "/home/jaganadhg/Desktop/Docs_New/kgisl/model/lm/wsj/wlist5o.dic"
wavfile = "/home/jaganadhg/Desktop/Docs_New/kgisl/sa1.wav"
recognised = decodeSpeech(hmdir,lmd,dictd,wavfile)
print …Run Code Online (Sandbox Code Playgroud) 我有在树莓派 B++ 上运行的 python 代码,它使用 sounddevice 库,可让您使用 python 播放和录制声音。我已经成功安装了模块。我可以通过 python 命令行确认并输入 import sounddevice 因为 sd 可以正常工作,没有错误。我还通过在 python 命令行中输入 help ('modules') 进行确认,并且出现了 sounddevice 模块。仅当我在独立的 python 程序中运行此代码时,才会出现 ImportError: No module name sounddevice 。
希望有人可以提供帮助。
这是包含的代码:
将声音设备导入为 SD
错误:
导入错误:没有模块名称 sounddevice
我有一个连接到树莓派3的USB麦克风和扬声器适配器.我已经在alsamixer上设置了所有内容.我还在主目录中设置了pcm.!default sysdefault:0in文件.asoundrc,它将usb音频适配器设置为默认音频卡.
我跑了:aplay -l,输出是:
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
Subdevices: 7/8
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Subdevice #7: subdevice #7
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: Device [USB PnP Sound Device], device 0: USB …Run Code Online (Sandbox Code Playgroud)