English speech recognition with python [speech to text]

Let's transcribe English

I will introduce the recognition online (with wifi) and the recognition offline (without wifi) respectively.

environment

ubuntu 18.04 python3


Online recognition

Use google. Install the environment with the following command.

python


pip3 install SpeechRecognition --user
sudo apt-get install portaudio19-dev
sudo apt-get install python-pyaudio python3-pyaudio
pip3 install pyaudio

Operation check

google_test.py


import speech_recognition as sr  

# get audio from the microphone                                                                       
r = sr.Recognizer()                                                                                   
with sr.Microphone() as source:  
    r.adjust_for_ambient_noise(source)                                                                     
    print("Speak:")                                                                                   
    audio = r.listen(source)   

try:
    print("-----------detect!----------\n",r.recognize_google(audio))
except sr.UnknownValueError:
    print("Could not understand audio")
except sr.RequestError as e:
    print("Could not request results; {0}".format(e))

I think the accuracy is relatively good

Offline recognition

Use pocketsphinx. Install the environment with the following command.

python


sudo apt-get install -y python python-dev python-pip build-essential swig git libpulse-dev
sudo apt-get install libasound2-dev
git clone https://github.com/cmusphinx/pocketsphinx-python.git
sudo pip install pocketsphinx

Operation check

pocket_test.py


from pocketsphinx import LiveSpeech
for phrase in LiveSpeech():
    print("-----------detect!----------\n",phrase) 

If the characters are output, it is successful.

"https://pypi.org/project/pocketsphinx/" Please refer to the various sample codes on this page.


You can improve the accuracy by creating your own dictionary and limiting the sentences that can be recognized. I will show you how to make your own dictionary at a later date. 2020/8/16: Updated about original dictionary ↓ "https://qiita.com/hir-osechi/items/7d1b100c721f34896a90"

Recommended Posts

English speech recognition with python [speech to text]
Speech to speech in python [text to speech]
Easy introduction of speech recognition with Python
Speech recognition in Python
The easiest way to synthesize speech with python
Connect to BigQuery with Python
Speech recognition by Python MFCC
Connect to Wikipedia with Python
Post to slack with Python 3
Switch python to 2.7 with alternatives
Write to csv with Python
Try face recognition with Python
Send experiment results (text and images) to slack with Python
Number recognition in images with Python
Python: How to use async with
Link to get started with python
GOTO in Python with Sublime Text 3
[Python] Write to csv file with Python
Create folders from '01' to '12' with python
Nice to meet you with python
Try to operate Facebook with Python
Text extraction with AWS Textract (Python3.6)
Output to csv file with Python
Text mining with Python ① Morphological analysis
Convert list to DataFrame with python
Enable Python raw_input with Sublime Text 3
MP3 to WAV conversion with Python
To do tail recursion with Python2
I tried Watson Speech to Text
How to get started with Python
What to do with PYTHON release?
Try face recognition with python + OpenCV
Unable to install Python with pyenv
Face recognition with camera with opencv3 + python2.7
How to use FTP with Python
Use Windows 10 speech synthesis with Python
Speak Japanese text with OpenJTalk + python
How to calculate date with python
Easily post to twitter with Python 3
I want to debug with Python
I want to do a full text search with elasticsearch + python
Try to reproduce color film with Python
I tried using Azure Speech to Text.
Try logging in to qiita with Python
Convert memo at once with Python 2to3
Streaming speech recognition with Google Cloud Speech API
HTML email with image to send with python
Memo to ask for KPI with python
Python to remember only with hello, worlds
Output color characters to pretty with python
Introduction to Python Image Inflating Image inflating with ImageDataGenerator
Output Python log to console with GAE
Convert Excel data to JSON with python
Convert Hiragana to Romaji with Python (Beta)
Fractal to make and play with Python
I wanted to solve ABC160 with Python
Connect to MySQL with Python within Docker
How to work with BigQuery in Python
[Introduction to Python] Let's use foreach with Python
Single pixel camera to experience with Python
[Python] Introduction to CNN with Pytorch MNIST