利用Python和API轻松实现:语音转文字,文字转语音。
语音转文字(支持实时麦克风输入和从音频文件读入):
百度 API
科大讯飞 API
SpeechRecognition (CMU PocketSphinx)
文字转语音:
pyttsx3
Environment
Python 3.6.7
MacOS(以下环境配置方式均基于Mac系统,其他系统的配置方式可能会有一些不同)
Speech to Text
百度
在 https://cloud.baidu.com/product/speech 申请API。
文档:http://ai.baidu.com/docs#/ASR-API
Configuration
安装:
pip install baidu-aip
在 speech_to_text_baidu() 中填入APPID、API_KEY、SECRET_KEY:
APP_ID = ""API_KEY = ""SECRET_KEY = ""
(也可以直接使用REST API:Demo
Usage
from 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)
科大讯飞