+
95
-

回答

1、python语音识别可以使用speech_recognition

安装pip install speech_recognition

识别代码:

# -*- coding: utf-8 -*-
# /usr/bin/python
import speech_recognition as sr
r = sr.Recognizer() #调用识别器
test = sr.AudioFile("/data/wwwroot/default/asset/voice.flac") #导入语音文件
with test as source:
audio = r.record(source)
type(audio)
c=r.recognize_sphinx(audio, language='zh-cn') #识别输出
print(c)

注意:pocketsphinx需要安装的中文语言、声学模型

下载地址:http://sourceforge.net/projects/cmusphinx/files/Acoustic%20and%20Language%20Models/

800_auto

在这个文件夹中添加进入刚刚解压的文件,需要注意:把解压出来的zh_cn.cd_cont_5000文件夹重命名为acoustic-model、zh_cn.lm.bin命名为language-model.lm.bin、zh_cn.dic中dic改为dict格式。

800_auto

2、文字转语音,安装pyttsx3

 pip install pyttsx3

daiam ru

import pyttsx3

def Word_VR(word, speed=50):
engine = pyttsx3.init()
# 设置新的语音音量, 音量最小为 0, 最大为 1
engine.setProperty('volume', 1)
voices = engine.getProperty('voices')
# 改变语速 范围为0-200 默认值为200
rate = engine.getProperty('rate')
engine.setProperty('rate', rate+ speed)
#voices[0]是男声,voices[1]是女生
engine.setProperty('voice', voices[0].id)
# engine.setProperty("voice", "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_ZH - CN_HUIHUI_11.0")
engine.say(word)
engine.runAndWait()

if __name__=='__main__':
Word_VR("你好,小辰", 60)


网友回复

我知道答案,我要回答