文本转换为语音
使用pyttsx
pip install pyttsx3
有时候需要管理员权限 ,添加--user
pip install pyttsx3 --user
import pyttsx3 as pyttsxengine=pyttsx.init()engine.say('你好啊')engine.runAndWait()
使用SAPI
from win32com.client import Dispatchspeaker=Dispatch('SAPI.SpVoice')speaker.Speak('大家好')del speaker
使用SpeechLib
实现文本转换语音
安装pip install comtypes
from comtypes.client import CreateObjectfrom comtypes.gen import SpeechLibegine=CreateObject('SAPI.SpVoice')stream=CreateObject('SAPI.SpFileStream')infile='demo.txt'outfile='demo.wav'stream.open(outfile,SpeechLib.SSFMCreateForWrite)egine.AudioOutputStream=streamf=open(infile,'r',encoding='utf-8')theText=f.read()f.close()egine.speak(theText)stream.close()
使用PocketSphinx
安装pip install PocketSphinx
pip install SpeechRecognition
import speech_recognition as sraudio_file='demo.wav'r=sr.Recognizer()with sr.AudioFile(audio_file) as source:audio=r.record(source)print('文本内容',r.recognize_sphinx(audio))

