Created
June 2, 2024 13:07
-
-
Save sushmithapopuri/ddb89f4863bcc87dfbc63a8a45685a46 to your computer and use it in GitHub Desktop.
speech to text and text to spech
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # import pandas as pd | |
| # df = pd.read_json('test.json') | |
| # print(df.shape[0]) | |
| # Python program to translate | |
| # speech to text and text to speech | |
| # import speech_recognition as sr | |
| import pyaudio | |
| # Initialize the recognizer | |
| # r = sr.Recognizer() | |
| # Function to convert text to | |
| # speech | |
| def SpeakText(command): | |
| print(command) | |
| # Initialize the engine | |
| # engine = pyttsx3.init() | |
| # engine.say(command) | |
| # engine.runAndWait() | |
| # def listen_to_mic(): | |
| # while(1): | |
| # try: | |
| # with sr.Microphone() as source2: | |
| # r.adjust_for_ambient_noise(source2, duration=0.2) | |
| # audio2 = r.listen(source2) | |
| # MyText = r.recognize_google(audio2) | |
| # MyText = MyText.lower() | |
| # print("Did you say "+MyText) | |
| # except sr.RequestError as e: | |
| # print("Could not request results; {0}".format(e)) | |
| # except sr.UnknownValueError: | |
| # print("unknown error occured") | |
| # print(sr.__version__) # just to print the version not required | |
| # r = sr.Recognizer() | |
| # my_mic = sr.Microphone(device_index=1) #my device index is 1, you have to put your device index | |
| # with my_mic as source: | |
| # print("Say now!!!!") | |
| # r.adjust_for_ambient_noise(source) #reduce noise | |
| # audio = r.listen(source) #take voice input from the microphone | |
| # print(type(audio)) | |
| # print(audio) | |
| # print(r.recognize_google(audio)) #to print voice into text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment