Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Voice Assistant using python
Next article icon

Speech recognition means converting spoken words into text. It used in various artificial intelligence applications such as home automation, speech to text, etc. In this article, you’ll learn how to do basic speech recognition in Python using the Google Speech Recognition API.

Step 1: Install Required Library

We’ll use theSpeechRecognition library in Python. To install it open your terminal or command prompt and run:

!pip install SpeechRecognition

Step 2: Upload your Audio File

When you run the below code it will ask you to upload a file from your computer. Use a clear .wav file for best results. You can download sample audio file from here.

Python
fromgoogle.colabimportfilesuploaded=files.upload()

Step 3: Convert Audio to Text

If you already have an audio file like a .wav file, you can use this method instead:

Python
importspeech_recognitionassrrecognizer=sr.Recognizer()filename=list(uploaded.keys())[0]withsr.AudioFile(filename)assource:print("Reading audio...")audio_data=recognizer.record(source)try:print("\nRecognized Text:")text=recognizer.recognize_google(audio_data)print(text)exceptsr.UnknownValueError:print("Sorry, could not understand the audio.")exceptsr.RequestError:print("Could not connect to Google API.")

Output:

Speech-to-text
Speech to text

Speech recognition in Python is very easy with the help ofGoogle Speech API. You can use your voice to control programs, take notes or even build voice assistants.

You can download source code fromhere.


D

Deepak Srivatsav
Improve

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp