• Stars
    star
    247
  • Rank 163,131 (Top 4 %)
  • Language
    Python
  • Created over 5 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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 = "人类的本质是复读机")

More Repositories

1

playground-macos

My portfolio website simulating macOS's GUI, developed with React and UnoCSS.
TypeScript
2,900
star
2

Speech-Emotion-Recognition

Speech emotion recognition implemented in Keras (LSTM, CNN, SVM, MLP) | 语音情感识别
Python
648
star
3

vuepress-theme-gungnir

A blog theme for VuePress 2.
TypeScript
314
star
4

oh-vue-icons

A Vue component for importing inline SVG icons from different popular icon packs easily.
JavaScript
205
star
5

Text-Classification

PyTorch implementation of some text classification models (HAN, fastText, BiLSTM-Attention, TextCNN, Transformer) | 文本分类
Python
126
star
6

pcalg-py

Implement PC algorithm in Python | PC 算法的 Python 实现
Python
88
star
7

Fishmail

奇怪的摸鱼工具增加了:装作在 Gmail 上查邮件的样子看知乎摸鱼,从而降低我上班摸鱼时的不安全感
Vue
65
star
8

Just-a-Cube

A rubik's cube solver | 魔方还原(层先法 + Two-phase)
JavaScript
54
star
9

oh-my-cv

Write your curriculum vitae in Markdown online.
TypeScript
51
star
10

blog.zxh.io

My blog 🧐, powered by VuePress 2, themed by Gungnir.
CSS
36
star
11

flint

A toy deep learning framework implemented in pure Numpy from scratch. Aka homemade PyTorch lol.
Python
30
star
12

jekyll-theme-gungnir

A blog theme for Jekyll.
SCSS
17
star
13

what-if

My messy notebook, built with VuePress 2.
TypeScript
17
star
14

renovamen.github.io

My personal website 🤔
TypeScript
14
star
15

Legend-of-Zeld

Spring 2018 User Interface Interaction - A web page for "The Legend of Zelda: Breath of the Wild" | 塞尔达传说:荒野之息
CSS
12
star
16

Operating-Systems

Spring 2018 Operating Systems - Assignments (Elevator Scheduling, Memory Management and File Management) | 操作系统课程项目(电梯调度,内存管理,文件管理)
Java
11
star
17

KG-Application-Papers

Paper list about application of Knowledge Graph | 知识图谱的应用相关论文
10
star
18

midgard

Hey adventurer! Why not help me with retrieving my curriculum vitae fragments back! | 来帮我找简历吗勇士!
TypeScript
10
star
19

Image-Captioning

PyTorch re-implementation of some papers on image captioning | 图像描述
Python
7
star
20

metallic

A clean, lightweight and modularized PyTorch meta-learning library.
Python
7
star
21

wordle-helper

Help you solve the Wordle puzzles when your vocabulary failes you.
TypeScript
5
star
22

Ratom

Spring 2019 Introduction to Cybersecurity - A simple cross platform rat (remote access trojan)
Python
4
star
23

Gomoku

Fall 2016 C Programming - A Gomoku AI based on Minimax Algorithm with Alpha-beta pruning | 基于极大极小值搜索 + Alpha-beta 剪枝的五子棋人工智障
C
3
star
24

AntiFood

深夜放毒反击系统(基于酷 Q 和 NoneBot)
Python
3
star
25

OI-ACM

My solutions for OI / ACM problems - 退役蒟蒻的人生回顾
C++
3
star
26

Just-Movies

Spring 2019 Web System and Technology - Assigment: Assignment: A movie web app using Django and Vue | Django + Vue 实现的电影 Web 应用
Vue
3
star
27

gitbook-plugin-katex

Math typesetting using KaTex into Gitbook. Update Katex to the latest version (0.11.1) and support single '$' for inline math.
JavaScript
2
star
28

HUAJI_OS

Spring 2018 Operating System - Final Project | 操作系统课程设计,修改了 ORANGES 的源码
C
2
star
29

torchop

A collection of some attention / convolution operators implemented using PyTorch.
Python
2
star
30

Galaxy-Voyager

Spring 2019 Web System and Technology - Final Project: A game
JavaScript
2
star
31

alkaid

PyTorch reinforcement learning toolbox.
Python
1
star
32

Stupid-Torch

一个沙雕安卓手电筒 app,在有光的地方亮,没有光的地方绝对不亮
Java
1
star
33

Renovamen

1
star
34

Just-a-Cat

Fall 2018 SOA and Web Services - Individual Assignment: An Android app integrating some Web APIs
Java
1
star
35

Byzantine

Implement the Om(n, m) algorithm for solving the Byzantine generals problem | 拜占庭口头消息算法的 Python 实现
Python
1
star
36

StockBot

A chatbot based on Rasa NLU aims to provide stock and weather information implemented by Python | 基于 Rasa NLU 的提供股票和天气信息的聊天机器人
Jupyter Notebook
1
star