In this article i want to show you an example of Python With Google Speech, so Speech Recognition is a library for performing speech recognition, with support for several engines and APIs, online and offline.

Speech recognition engine/API support

So now for this first of all you need to install speechRecognition Library in Python ,

First, make sure you have all the requirements listed in the “Requirements” section.

The easiest way to install this is using pip install SpeechRecognition.

Otherwise, download the source distribution from PyPI, and extract the archive.

In the folder, run python setup.py install.

Requirements

  • Python 2.6, 2.7, or 3.3+ (required)
  • PyAudio 0.2.11+ (required only if you need to use microphone input, Microphone)
  • PocketSphinx (required only if you need to use the Sphinx recognizer, recognizer_instance.recognize_sphinx)
  • Google API Client Library for Python (required only if you need to use the Google Cloud Speech API, recognizer_instance.recognize_google_cloud)
  • FLAC encoder (required only if the system is not x86-based Windows/Linux/OS X)

So now this is the complete code for Python Speech Recognition With Google Speech

import speech_recognition as sr



def main():

    r = sr.Recognizer()

    with sr.Microphone() as source:
        r.adjust_for_ambient_noise(source)

        print("Please say something")

        audio = r.listen(source)

        print("Recognizing Now .... ")


        # recognize speech using google

        try:
            print("You have said \n" + r.recognize_google(audio))
            print("Audio Recorded Successfully \n ")


        except Exception as e:
            print("Error :  " + str(e))




        # write audio

        with open("recorded.wav", "wb") as f:
            f.write(audio.get_wav_data())


if __name__ == "__main__":
    main()

So at the top first we have created a recognizer object, also for removing noises we need to add this line of code

r.adjust_for_ambient_noise(source)

And in here we are recognizing the speech using Google Speech

print("You have said \n" + r.recognize_google(audio))

In here we are going to record the audio

        with open("recorded.wav", "wb") as f:
            f.write(audio.get_wav_data())

Now run the code and this will be the result

Python Speech To Text Converter

#python #machine-learning #data-science

How to Convert Speech to Text in Python using Google Speech
81.55 GEEK