<jupyter_start><jupyter_text>Speech to Text In this Project, we will be running a very easy Speech-to-Text Program using the Google Speech Recognition API. This only requires two main libraries which you will need to install. After that, the program will input the audio, and then convert it into text. By default, the language used by the Google API will be English. You can also try other languages, as you will see in the rest of the program.<jupyter_code># You will first need to install the Port Audio and Pyaudio Libraries. The easiest way to do this is,
# if you have Anaconda, open the Environments space and then install the package directly to your Environment.
# Here, you install the Speech Recognition Library. Remove the hash to install it.

#pip install SpeechRecognition
import speech_recognition as sr
r=sr.Recognizer()
with sr.Microphone() as source:
    print("Hi, welcome to the speech recognition program! Try it by saying something:");
    audio=r.listen(source)
    print("Great job! Let's see what you said... ")
    
try:
    print("Text version: "+r.recognize_google(audio));

# In case the program cannot understand the audio, it will provide an error.
except sr.UnknownValueError:
    print("Error, please try again.")

# Sometimes the code might take very long to run, as it is picking up too much extra noise.<jupyter_output><empty_output><jupyter_text>If you want to print the text in another language, say, French, type in the following code.<jupyter_code>with sr.Microphone() as source:
    print("Hi, welcome to the speech recognition program! Try it by saying something:");
    audio=r.listen(source)
    print("Great job! Let's see what you said... ")
    
try:
    print("Text version: "+r.recognize_google(audio, language='fr-FR'));

except sr.UnknownValueError:
    print("Error, please try again.")<jupyter_output><empty_output><jupyter_text>It can also understand and print in the alphabet of a given Language. For example, consider the Indian Language, 'Hindi', which has its own script.<jupyter_code>with sr.Microphone() as source:
    print("Hi, welcome to the speech recognition program! Try it by saying something:");
    audio=r.listen(source)
    print("Great job! Let's see what you said... ")
    
try:
    print("Text version: "+r.recognize_google(audio, language='hi-IN'));

except sr.UnknownValueError:
    print("Error, please try again.")<jupyter_output><empty_output><jupyter_text>To know more about which languages the API supports, click here - https://cloud.google.com/speech-to-text/docs/languages Suppose you want to convert an entire audio file into text. All you need to do is define it, and after that, replace it in the code.Note: This works only for WAV, AIFF, and FLAC.<jupyter_code># Your audio file
myaudio = ("myaudio.wav") 
with sr.AudioFile(myaudio) as source:
    print("Hi, welcome to the speech recognition program! Try it by saying something:");
    # We change "listen" to "record".
    audio=r.record(source)
    print("Great job! Let's see what you said... ")
    
try:
    print("Text version: "+r.recognize_google(audio));

except sr.UnknownValueError:
    print("Error, please try again.")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09278350515463918, 'fraction_numerical': 0.0, 'mean_word_length': 4.492281303602058, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '598103', 'license': 'MIT', 'n_tokens_mistral': 919, 'n_tokens_neox': 889, 'n_words': 396, 'path': 'My Project 5 (a) - Speech to Text.ipynb', 'repo_name': 'nikita-15/10-Minute-Programs-for-Python-Beginners', 'size': '3201'}