#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模块 语音转文字
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/ 中文包的网址
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?