-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAO.py
More file actions
48 lines (42 loc) · 1.58 KB
/
Copy pathAO.py
File metadata and controls
48 lines (42 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import speech_recognition as sr
import boto3
import openai
import os
from pydub import AudioSegment
from pydub.playback import play
def transcribe_audio(audio_file_path):
# Amazon Transcribe
transcribe = boto3.client('transcribe')
job_name = "transcription_job"
job_uri = audio_file_path
transcribe.start_transcription_job(
TranscriptionJobName=job_name,
Media={'MediaFileUri': job_uri},
MediaFormat='wav',
LanguageCode='en-US'
)
while True:
status = transcribe.get_transcription_job(TranscriptionJobName=job_name)
if status['TranscriptionJob']['TranscriptionJobStatus'] in ['COMPLETED', 'FAILED']:
break
print("Transcribing...")
return status['TranscriptionJob']['Transcript']['TranscriptFileUri']
def main():
recognizer = sr.Recognizer()
# Adjust the microphone device index as needed
microphone = sr.Microphone(device_index=1) # Assuming device_index=1 for Logitech BRIO
with microphone as source:
print("Adjusting for ambient noise, please wait...")
recognizer.adjust_for_ambient_noise(source)
print("Listening...")
audio = recognizer.listen(source)
try:
print("Recognizing...")
text = recognizer.recognize_google(audio)
print("You said: " + text)
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))
if __name__ == "__main__":
main()