当前位置: 首页 > news >正文

哈尔滨大型网站设计公司成都网站搜索排名优化公司

哈尔滨大型网站设计公司,成都网站搜索排名优化公司,专业做胶粘剂招聘网站,b2c商城网站合同1. 首先安装依赖库 pip install playsound # 该库用于播放音频文件 pip install speech_recognition # 该库用于语音识别 pip install PocketSphinx # 语音识别模块中只有sphinx支持离线的,使用该模块需单独安装 pip install pyttsx3 # 该库用于将文本转换为语音播…

1. 首先安装依赖库

pip install playsound # 该库用于播放音频文件
pip install speech_recognition # 该库用于语音识别
pip install PocketSphinx # 语音识别模块中只有sphinx支持离线的,使用该模块需单独安装
pip install pyttsx3 # 该库用于将文本转换为语音播放
pip install comtypes # 该库可以从文本文件中获取输入转换为语音文件

2. 播放音频文件 

from playsound import playsound 
playsound('audio_files\cnhello.mp3')

3. 语音识别

默认只识别英文,如果需要支持中文,需要下载中文模型包,下载地址如下:

CMU Sphinx - Browse /Acoustic and Language Models at SourceForge.net 

下载完解压到sphinx安装路径下:

D:\install\Anaconda\Lib\site-packages\speech_recognition\pocketsphinx-data

 

import speech_recognition as sr
r = sr.Recognizer()
harvard = sr.AudioFile('audio_files\harvard.wav')
with harvard as source:
#     r.adjust_for_ambient_noise(source) # 消除环境背景音audio = r.record(source) # record()函数,将整个音频文件读入AudioData实例
print(type(audio))    
r.recognize_sphinx(audio) 

4. 通过麦克风输入并识别

import speech_recognition as sr
mic = sr.Microphone()
with mic as source:r.adjust_for_ambient_noise(source)audio = r.listen(source)r.recognize_sphinx(audio)

5. 文本转语音播放

import pyttsx3
engine = pyttsx3.init()
engine.say("hello world")
engine.say("你好")
engine.runAndWait()
engine.stop()

6. 文本转语音

# 文本转语音
from comtypes.client import CreateObject
from comtypes.gen import SpeechLibengine = 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()

7. 语音转文本(英文识别)

# 语音文件转文本文件
import speech_recognition as sr
r = sr.Recognizer()harvard = sr.AudioFile('demo_audio.wav')
with harvard as source:
#     r.adjust_for_ambient_noise(source)audio = r.record(source)r.recognize_sphinx(audio, language='en-US')

>>'hello everyone my name is bob'

8. 语音转文本(中文识别)

# 语音文件转文本文件
import speech_recognition as sr
r = sr.Recognizer()harvard = sr.AudioFile('demo_audio.wav')
with harvard as source:
#     r.adjust_for_ambient_noise(source)audio = r.record(source)r.recognize_sphinx(audio, language='zh-CN')

 >> '好好 学习 天天 向上'

参考:

python实现语音识别功能

从0开始语音识别

http://www.ds6.com.cn/news/44718.html

相关文章:

  • 淘宝网页版登录入口官方上海企业网站seo
  • 怎么提高网站流量重庆百度快照优化排名
  • 网页设计门户网站品牌营销策略论文
  • 网站设计平台老司机们用的关键词有哪些
  • 网站建设能在家工作室seo收费低
  • 做网站美工要学什么免费推广方法
  • 镇江市官网郑州seo技术
  • 怎么做国内网站南京seo收费
  • 义务网站建设收录优美的图片app
  • 做国外购物网站完整企业网站模板
  • 购物网站线下推广方案企业网络推广的方式有哪些
  • 网站建设开票属于什么服务必应搜索引擎怎么样
  • 网站建设需要哪些硬件宁波优化推广找哪家
  • 提升网站建设百度seo收录软件
  • 梅州做网站多少钱营销推广方案范文
  • 网站建设论文伯乐在线最彻底的手机优化软件
  • 移动版网站建设网络推广外包公司干什么的
  • 个人网站模板html代码免费电商网站建设制作
  • 原创手做网站搜索软件排行榜前十名
  • 设计公司网站建设费用电商seo优化是什么
  • 网站网站设计国外引擎搜索
  • 扬中市人才网官网优化软件下载
  • 如何通过后台管理在网站的logo后台上加链接我想做个网站怎么做
  • 好123上网主页seo优化技巧有哪些
  • 推广平台排名前十名网站制作优化排名
  • 郑州做网站的公司msgg360收录批量查询
  • 石家庄学做网站建设培训小说百度搜索风云榜
  • 网站制作 佛山百度品牌广告多少钱
  • 山西建设厅报名网站域名注册服务网站
  • 网站设计服务培训公司排名