pythonの音声認識

4665 ワード

まずpython 36に基づいてモジュールをインストールします
pip install pyttsx3
pip install PocketSphinx
pip install SpeechRecognition
pip install comtypes

txtファイルによる音声ファイルの作成
 from comtypes.client import CreateObject
 engine=CreateObject("SAPI.SpVoice")
 stream=CreateObject('SAPI.SpFileStream')
 from comtypes.gen import SpeechLib
 infile='hello.txt'
 outfile='demo_audio.wav'
 stream.Open(outfile,SpeechLib.SSFMCreateForWrite)
 engine.AudioOutputStream=stream
 f=open(infile,'r',encoding='utf-8')
 theText=f.read()
 f.close()
 engine.speak(theText) 
 stream.close()

次に、以前に作成したdemo_を利用します.audio.wavの音声ファイル
import speech_recognition as sr 
audio_file='demo_audio.wav' 
r=sr.Recognizer() 
with sr.AudioFile(audio_file) as source: 
    audio =r.record(source) 
try: # print('    :',r.recognize_sphinx(audio,language="zh_CN")) 
    print('    :',r.recognize_sphinx(audio)) 
except Exception as e: 
       ``print(e)
  pyhton                      
`
https://sourceforge.net/projects/cmusphinx/files/Acoustic%20and%20Language%20Mo dels/
`