基于pyttsx3实现文字转语音
engine = pyttsx3.init()
engine.say("hello")
engine.runAndWait()
将这个语音存为音频:
engine.save_to_file('hello','test.wav')
基于speech_recognition实现语音转文字
# 读取音频文件
r = sr.Recognizer()
f = sr.AudioFile("D:\\python\\ko\\function\\语音转换\\test.wav")
with f as source:
data = r.record(source)
# print(type(data))
sp = r.recognize_google(data,language='zh-CN',show_all=True)
list = sp['alternative']
for i in range(len(list)):
print(list[i])
【注: 修改 D:\python\Python\Lib\site-packages\speech_recognition路径下init.py中recognize_google()函数url变量
url = "http://www.google.cn/speech-api/v2/recognize?{} --- 将com改为cn】