python或bash中的pocketsphinx简单识别

python或bash中的pocketsphinx简单识别,python,bash,pocketsphinx,Python,Bash,Pocketsphinx,就我对指挥部的认识而言: pocketsphinx_continuous -hmm /usr/local/share/pocketsphinx/model/en-us/en-us \ -lm 3199.lm -dict 3199.dic -inmic yes 我想让它,如果承认是这样做,如果没有这样做 我该怎么做呢?enyone有简单的工作示例吗?最好用Python,而不是bash。大概是这样的: from os import environ, path import pyaudio from

就我对指挥部的认识而言:

pocketsphinx_continuous -hmm /usr/local/share/pocketsphinx/model/en-us/en-us \
-lm 3199.lm -dict 3199.dic -inmic yes
我想让它,如果承认是这样做,如果没有这样做
我该怎么做呢?enyone有简单的工作示例吗?

最好用Python,而不是bash。大概是这样的:

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()

更多python示例可在

中找到,最好使用python,而不是bash。大概是这样的:

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()

中提供了更多python示例,最好使用python,而不是bash。Python示例可以在源代码中找到,最好是用Python,而不是用bash。Python示例可以在源代码中找到。