#pyttsx3文字转语音
import pyttsx3
engine2 = pyttsx3.init()
while True:
content = input('请输入播放内容:')
engine2.say(content)
engine2.runAndWait()
#文字转语音
from win32com.client import Dispatch
msg = '你好'
speaker = Dispatch('SAPI.SpVoice')
speaker.Speak(msg)
del speaker
#comtypes模块 文字文件转语音文件(当前仅支持英文)
from comtypes.client import CreateObject
from comtypes.gen import SpeechLib
engine = CreateObject('SAPI.SpVoice')
stream = CreateObject('SAPI.SpFileStream')
infile = 'demo.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()
#PocketSphinx模块 SpeechRecognition模块 语音转文字标签:文字,python,speaker,语音,print,import,audio From: https://www.cnblogs.com/lld76/p/15995227.html
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)
#https://sourceforge.net/projects/cmusphinx/files/Acoustic%20and%20Language%20Models/ 中文包的网址