Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Audio_to_Text.py #416

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Python/audio_to_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from email.mime import audio
import sounddevice as sd
import wavio as wv
import speech_recognition as sr

def speech_to_text(duration:int, freq = 44100) :
print(f"Listening for {duration} sec...")
recording = sd.rec(int(duration * freq),
samplerate=freq, channels=2)
sd.wait()
print("Please Wait...")
wv.write("recording1.wav", recording, freq, sampwidth=2)
r = sr.Recognizer()
with sr.AudioFile('./recording1.wav') as source:
audio_data = r.record(source)
text = r.recognize_google(audio_data)
return text

if __name__ == "__main__":

# duration = int(input("Durations in seconds : "))
duration = 5 # You can change the duration here
audio_text = speech_to_text(duration)
print("Text : ",audio_text)