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

运营网站销售队伍建设与管理2024年2月疫情又开始了吗

运营网站销售队伍建设与管理,2024年2月疫情又开始了吗,佛山 两学一做 网站,如何找到网站管理员文章目录 理论文本转换为语音使用 pyttsx使用 SAPI使用 SpeechLib 语音转换为文本 代码和效果01使用pyttsx实现文本_语音02使用SAPI实现文本_语音03使用SpeechLib实现文本_语音04使用PocketSphinx实现语音转换文本 理论 语音识别技术,也被称为自动语音识别&#xf…

文章目录

  • 理论
    • 文本转换为语音
      • 使用 pyttsx
      • 使用 SAPI
      • 使用 SpeechLib
    • 语音转换为文本
  • 代码和效果
    • 01使用pyttsx实现文本_语音
    • 02使用SAPI实现文本_语音
    • 03使用SpeechLib实现文本_语音
    • 04使用PocketSphinx实现语音转换文本

理论

语音识别技术,也被称为自动语音识别,目标是以电脑自动将人类的语音内容转换为相 应的文字和文字转换为语音。

文本转换为语音

使用 pyttsx

使用名为 pyttsx 的 python 包,你可以将文本转换为语音。直接使用 pip 就可以进行安装, 命令如下:

pip install pyttsx3

【示例】使用 pyttsx 实现文本转换语音

import pyttsx3 as pyttsx 
engine=pyttsx.init() 
engine.say('你好 pyttsx') 
engine.runAndWait() 

使用 SAPI

在 python 中,你也可以使用 SAPI 来做文本到语音的转换。

【示例】使用 SAPI 实现文本转换语音

from win32com.client import Dispatch 
msg="你好 SAPI" 
speaker = Dispatch('SAPI.SpVoice') 
speaker.Speak(msg) 
del speaker 

使用 SpeechLib

使用 SpeechLib,可以从文本文件中获取输入,再将其转换为语音。先使用 pip 安装, 命令如下:

pip install comtypes 

【示例】使用 SpeechLib 实现文本转换语音

from comtypes.client import CreateObject 
engine=CreateObject("SAPI.SpVoice") 
stream=CreateObject('SAPI.SpFileStream') 
from comtypes.gen import SpeechLib 
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 PocketSphinx 是一个用于语音转换文本的开源 API。它是一个轻量级的语音识别引擎, 尽管在桌面端也能很好地工作,它还专门为手机和移动设备做过调优。
首先使用 pip 命令安装所需模块,命令如下:

pip install PocketSphinx 
pip install SpeechRecognition 

【示例】使用 PocketSphinx 实现语音转换文本

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) 

注意:
□ 安装完 speech_recognition 之后是不支持中文的,需要在 Sphinx 语音识别工具包里 面 下 载 对 应 的 普 通 话 升 学 和 语 言 模 型 。 下 载 地 址 https://sourceforge.net/projects/cmusphinx/files/Acoustic%20and%20Language%20Mo dels/
□ 将 下 载 好 的 普 通 话 升 学 和 语 言 模 型 放 到 安 装 speech_recognition 模 块 的 pocketsphinx-data 目录下。

代码和效果

01使用pyttsx实现文本_语音

import pyttsx3 as pyttsx
engine=pyttsx.init()
engine.say('好好学习')
engine.runAndWait()

复制到vscode或其他,运行时需要 pip install pyttsx3
在这里插入图片描述
在这里插入图片描述

02使用SAPI实现文本_语音

from win32com.client import Dispatch
speaker=Dispatch('SAPI.SpVoice')
speaker.Speak('大家好')
del speaker

在这里插入图片描述

03使用SpeechLib实现文本_语音

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()

需要将文本放到电脑根目录下
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

04使用PocketSphinx实现语音转换文本

import speech_recognition as sr
audio_file='demo_audio.wav'
r=sr.Recognizer()
#打开语音文件
with sr.AudioFile(audio_file) as source:audio=r.record(source)#将语音转换为文本
# print('文本内容:',r.recognize_sphinx(audio))
print('文本内容:',r.recognize_sphinx(audio,language='zh-CN'))

一、安装环境库
在这里插入图片描述
ModuleNotFoundError: No module named ‘speech_recognition’
是:pip install speechrecognition
在这里插入图片描述
再安装:pip install PocketSphinx
在这里插入图片描述

二、文件放根目录
在这里插入图片描述

http://www.hkea.cn/news/914456/

相关文章:

  • 济南网站建设公司川芎网络怎么注册自己的网址
  • linux下安装wordpress关键词优化排名查询
  • wordpress手机网站怎么做中央电视台一套广告价目表
  • 百家号如何给网站做推广推广方案是什么
  • 西安三网合一网站建设产品线上推广方案
  • 2023年免费b站入口百度网站优化
  • 响应式网站建设有利于seo网站发布与推广方案
  • 网页制作教程课件seo推广排名重要吗
  • 小规模纳税人企业所得税怎么征收广州seo招聘
  • 济南企业自助建站网络营销策划公司
  • iis 新建网站 要登录温州seo推广外包
  • 个人想做企业网站备案惠州seo代理商
  • 做公务员题的网站口红的推广软文
  • 福州网站建设 联系yanktcn 04上海百网优seo优化公司
  • 网站备案号如何获得网站建设营销推广
  • 物流网站开发公司西安 做网站
  • 商务信息网站怎么做网络视频营销策略有哪些
  • 社交做的最好的网站怎么开发一个网站
  • 教育品牌网站建设百度搜索推广和信息流推广
  • 虎门专业做网站对网络营销的认识有哪些
  • 投资理财培训网站建设抖音引流推广一个30元
  • 做景观设施的网站网络营销推广要求
  • 携程网站建设进度及实施过程网络营销的缺点及建议
  • 石家庄网站建设哪家专业中国联通腾讯
  • 能访问各种网站的浏览器百度一下网页搜索
  • 自己做网站花多少钱雅虎搜索
  • 哈尔滨招标信息网网站推广优化排名教程
  • 个人可以建论坛网站吗福清网络营销
  • 济南做网站优化价格百度推广网站一年多少钱
  • 做网上商城网站哪家好杭州seo靠谱