This is a simple Python script that demonstrates how to perform speech-to-text recognition using a microphone and the speech_recognition
library. It uses Google's speech recognition service to transcribe the audio.
To use this script, you'll need the following dependencies installed on your system:
- Python 3.x
speech_recognition
librarypyaudio
library (for microphone input)
-
Install Python 3.x from the official website.
-
Install
pip
, the package installer for Python, by following the instructions in the official documentation. -
Install
pyaudio
library by running the following command in a terminal or command prompt:
pip install pyaudio
If you encounter an error during installation, you may need to install portaudio
separately. You can download portaudio
from the official website or install it using a package manager such as Chocolatey.
- Install
speech_recognition
library by running the following command in a terminal or command prompt:
pip install SpeechRecognition
- Install Homebrew by following the instructions on the official website.
- Install Python 3.x by running the following command in a terminal:
brew install python
- Install
pyaudio
library by running the following command in a terminal:
brew install portaudio
pip install pyaudio
If you encounter an error during installation, you may need to specify the path to portaudio
manually. You can do this by running the following command instead:
pip install --global-option='build_ext' --global-option='-I/usr/local/include' --global-option='-L/usr/local/lib' pyaudio
- Install
speech_recognition
library by running the following command in a terminal:
pip install SpeechRecognition
- Open Jupyter Notebook and create a new notebook.
- Copy the following code into a cell:
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
print("Speak Anything :")
audio = r.listen(source)
try:
text = r.recognize_google(audio)
print("You said : {}".format(text))
except:
print("Sorry could not recognize what you said")
- Run the cell.
- Speak into your microphone when prompted by the script.
- The script will transcribe your speech and print the result to the console. If the script is unable to recognize your speech, it will print an error message.
- This script was adapted from the
speech_recognition
library's documentation.