2016-06-29 1 views

Répondre

0

La meilleure chose est d'utiliser python, quelque chose comme ceci:

import sys, os 
from pocketsphinx.pocketsphinx import * 
from sphinxbase.sphinxbase import * 
import pyaudio 

modeldir = "../../../model" 

# Create a decoder with certain model 
config = Decoder.default_config() 
config.set_string('-hmm', os.path.join(modeldir, 'en-us/en-us')) 
config.set_string('-dict', os.path.join(modeldir, 'en-us/cmudict-en-us.dict')) 
config.set_string('-kws', 'keyword.list') 

p = pyaudio.PyAudio() 
stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=1024) 
stream.start_stream() 

# Process audio chunk by chunk. On keyword detected perform action and restart search 
decoder = Decoder(config) 
decoder.start_utt() 
while True: 
    buf = stream.read(1024) 
    if buf: 
     decoder.process_raw(buf, False, False) 
    else: 
     break 
    if decoder.hyp() == "tv on": 
     print ("Detected keyword tv on, turning on tv") 
     os.system('beep') 
     decoder.end_utt() 
     decoder.start_utt() 
    if decoder.hyp() == "tv off": 
     print ("Detected keyword tv off, turning off tv") 
     os.system('beep beep') 
     decoder.end_utt() 
     decoder.start_utt()