2023年7月10日发(作者:)
python离线语⾳转⽂字_利⽤Python和API轻松实现:语⾳转⽂字,⽂字转语⾳利⽤Python和API轻松实现:语⾳转⽂字,⽂字转语⾳。语⾳转⽂字(⽀持实时麦克风输⼊和从⾳频⽂件读⼊):百度 API科⼤讯飞 APISpeechRecognition (CMU PocketSphinx)⽂字转语⾳:pyttsx3EnvironmentPython 3.6.7MacOS(以下环境配置⽅式均基于Mac系统,其他系统的配置⽅式可能会有⼀些不同)Speech to Text百度Configuration安装:pip install baidu-aip在 speech_to_text_baidu() 中填⼊APPID、API_KEY、SECRET_KEY:APP_ID = ""API_KEY = ""SECRET_KEY = ""(也可以直接使⽤REST API:DemoUsagefrom Speech_and_Text import speech_to_text_baidu# 从⽂件读⼊speech_to_text_baidu(audio_path = "path_of_audio",if_microphone = False)# 从麦克风读⼊speech_to_text_baidu(if_microphone = True)科⼤讯飞Configuration在 speech_to_text_ifly() 填⼊ APPID、API_KEY:URL = "/v1/service/v1/iat"APPID = ""API_KEY = ""要在讯飞管理⾯板中添加调⽤⽅api,否则会报错。Usagefrom Speech_and_Text import speech_to_text_ifly# 从⽂件读⼊speech_to_text_ifly(audio_path = "path_of_audio",if_microphone = False)# 从麦克风读⼊speech_to_text_ifly(if_microphone = True)SpeechRecognition使⽤了Python的语⾳识别库 SpeechRecognitionConfigurationSpeechRecognition安装:pip install SpeechRecognitionPyAudio使⽤麦克风进⾏输⼊# Mac上的安装⽅式xcode-select --install# 安装xcode, 已经装好的的话,执⾏的时候会提⽰# 先⽤homebrew安装portaudio(pyaudio需要的库),否则会提⽰:'portaudio.h' file not foundbrew remove portaudio# 先⽤homebrew卸载brew install portaudio# 重新安装sudo pip install pyaudio# 安装pyaudioPocketSphinxCMU Sphinx 是卡内基梅隆⼤学开发的开源语⾳识别引擎,可以离线⼯作,⽀持多种语⾔(包括中⽂)。PocketSphinx 是 CMU Sphinx 的 Python 封装接⼝。安装:pip install PocketSphinx添加中⽂语⾔包:查看 SpeechRecognition 包的安装路径('/path'):python -c "import speech_recognition as sr, as p; print(e(sr.__file__))"然后下载并解压 Mandarin Chinese 语⾔包,把 zh-CN ⽂件夹放⼊ '/path/pocketsphinx-data' 中Usagefrom Speech_and_Text import speech_to_text_cmu# 从⽂件读⼊speech_to_text_cmu(audio_path = "path_of_audio",if_microphone = False)# 从麦克风读⼊speech_to_text_cmu(if_microphone = True)Text to Speech使⽤了Python的⽂字转语⾳库 pyttsx3Configurationpip install pyttsx3pip install pyobjc # 依赖模块Usagefrom Speech_and_Text import text_to_speech# Exampletext_to_speech(sentence = "⼈类的本质是复读机")源码下载地址:
发布者:admin,转转请注明出处:http://www.yc00.com/xiaochengxu/1688932096a184904.html
评论列表(0条)