Skip to content

Commit b6526cd

Browse files
committed
added speech recognition tutorial
1 parent 65cd7b5 commit b6526cd

File tree

6 files changed

+48
-0
lines changed

6 files changed

+48
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
2929
- [How to Make an Image Classifier in Python using Keras](https://www.thepythoncode.com/article/image-classification-keras-python). ([code](machine-learning/image-classifier))
3030
- [How to Use Transfer Learning for Image Classification using Keras in Python](https://www.thepythoncode.com/article/use-transfer-learning-for-image-flower-classification-keras-python). ([code](machine-learning/image-classifier-using-transfer-learning))
3131
- [How to Perform Edge Detection in Python using OpenCV](https://www.thepythoncode.com/article/canny-edge-detection-opencv-python). ([code](machine-learning/edge-detection))
32+
- [How to Convert Speech to Text in Python](https://www.thepythoncode.com/article/using-speech-recognition-to-convert-speech-to-text-python). ([code](machine-learning/speech-recognition))
3233
- [Top 8 Python Libraries For Data Scientists and Machine Learning Engineers](https://www.thepythoncode.com/article/top-python-libraries-for-data-scientists).
3334

3435

90.7 KB
Binary file not shown.

Diff for: machine-learning/speech-recognition/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# [How to Convert Speech to Text in Python](https://www.thepythoncode.com/article/using-speech-recognition-to-convert-speech-to-text-python)
2+
To run this:
3+
- `pip3 install -r requirements.txt`
4+
- To recognize the text of an audio file named `16-122828-0002.wav`:
5+
```
6+
python recognizer;py 16-122828-0002.wav
7+
```
8+
**Output**:
9+
```
10+
I believe you're just talking nonsense
11+
```
12+
- To recognize the text from your microphone after talking 5 seconds:
13+
```
14+
python live_recognizer.py 5
15+
```
16+
This will record your talking in 5 seconds and then uploads the audio data to Google to get the desired output.
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import speech_recognition as sr
2+
import sys
3+
4+
duration = int(sys.argv[1])
5+
6+
# initialize the recognizer
7+
r = sr.Recognizer()
8+
print("Please talk")
9+
with sr.Microphone() as source:
10+
# read the audio data from the default microphone
11+
audio_data = r.record(source, duration=duration)
12+
print("Recognizing...")
13+
# convert speech to text
14+
text = r.recognize_google(audio_data)
15+
print(text)

Diff for: machine-learning/speech-recognition/recognizer.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import speech_recognition as sr
2+
import sys
3+
4+
filename = sys.argv[1]
5+
6+
# initialize the recognizer
7+
r = sr.Recognizer()
8+
9+
# open the file
10+
with sr.AudioFile(filename) as source:
11+
# listen for the data (load audio to memory)
12+
audio_data = r.record(source)
13+
# recognize (convert from speech to text)
14+
text = r.recognize_google(audio_data)
15+
print(text)

Diff for: machine-learning/speech-recognition/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
speech_recognition

0 commit comments

Comments
 (0)