GithubHelp home page GithubHelp logo

renovamen / speech-and-text Goto Github PK

View Code? Open in Web Editor NEW
277.0 4.0 66.0 65 KB

Speech to text (PocketSphinx, Iflytex API, Baidu API) and text to speech (pyttsx3) | 语音转文字(PocketSphinx、百度 API、科大讯飞 API)和文字转语音(pyttsx3)

Python 100.00%
speech-to-text text-to-speech speech-recognition

speech-and-text's Introduction

Speech-and-Text

语音转文字(支持实时麦克风输入和从音频文件读入):

  • 百度 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)

 

科大讯飞

https://www.xfyun.cn/services/voicedictation 申请API。

文档:https://doc.xfyun.cn/rest_api/index.html

Configuration

speech_to_text_ifly() 填入 APPID、API_KEY:

URL = "http://api.xfyun.cn/v1/service/v1/iat"
APPID = ""
API_KEY = ""

要在讯飞管理面板中添加调用方api,否则会报错。

Usage

from 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的语音识别库 SpeechRecognition

源码:https://github.com/Uberi/speech_recognition

 

Configuration

SpeechRecognition

安装:

pip install SpeechRecognition
PyAudio

使用麦克风进行输入

主页:http://people.csail.mit.edu/hubert/pyaudio/

# Mac上的安装方式

xcode-select --install	# 安装xcode, 已经装好的的话,执行的时候会提示

# 先用homebrew安装portaudio(pyaudio需要的库),否则会提示:'portaudio.h' file not found
brew remove portaudio	# 先用homebrew卸载
brew install portaudio	# 重新安装

sudo pip install pyaudio	# 安装pyaudio

Reference: https://stackoverflow.com/questions/33851379/pyaudio-installation-on-mac-python-3

PocketSphinx

CMU Sphinx 是卡内基梅隆大学开发的开源语音识别引擎,可以离线工作,支持多种语言(包括中文)。

源码:https://github.com/cmusphinx

PocketSphinx 是 CMU Sphinx 的 Python 封装接口。

源码:https://github.com/cmusphinx/pocketsphinx-python

安装:

pip install PocketSphinx

添加中文语言包:

查看 SpeechRecognition 包的安装路径('/path'):

python -c "import speech_recognition as sr, os.path as p; print(p.dirname(sr.__file__))"

然后下载并解压 Mandarin Chinese 语言包,把 zh-CN 文件夹放入 '/path/pocketsphinx-data'

 

Usage

from 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的文字转语音库 pyttsx3

源码:https://github.com/nateshmbhat/pyttsx3

文档:https://pyttsx3.readthedocs.io

Configuration

pip install pyttsx3
pip install pyobjc # 依赖模块

Usage

from Speech_and_Text import text_to_speech
# Example
text_to_speech(sentence = "人类的本质是复读机")

speech-and-text's People

Contributors

renovamen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

speech-and-text's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.