majweldon commited on
Commit
c64345b
·
1 Parent(s): ee474cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -15
app.py CHANGED
@@ -37,7 +37,7 @@ def transcribe(audio, history_type):
37
  messages = [{"role": "system", "content": role}]
38
 
39
  ######################## Read audio file, wait as necessary if not written
40
- max_attempts = 30
41
  attempt = 0
42
  audio_data = None
43
  samplerate = None
@@ -56,24 +56,20 @@ def transcribe(audio, history_type):
56
  return # Terminate the function or raise an exception if the file could not be opened
57
 
58
 
59
- ###### Create Dialogue Transcript from Audio Recording and Append(via Whisper)
60
- # Load the audio file (from filepath)
61
-
62
- #### Massage .wav and save as .mp3
63
- audio_data = audio_data.astype("float32")
64
- audio_data = (audio_data * 32767).astype("int16")
65
  #audio_data = audio_data.mean(axis=1)
 
 
66
  sf.write("Audio_Files/test.wav", audio_data, samplerate, subtype='PCM_16')
67
- if not os.path.exists("Audio_Files/test.wav"):
68
- print("Error: Failed to create test.wav file")
69
- return
70
  sound = AudioSegment.from_wav("Audio_Files/test.wav")
71
  sound.export("Audio_Files/test.mp3", format="mp3")
72
- if not os.path.exists("Audio_Files/test.mp3"):
73
- print("Error: Failed to create test.mp3 file")
74
- return
75
 
76
- #Send file to Whisper for Transcription
 
 
 
77
  audio_file = open("Audio_Files/test.mp3", "rb")
78
 
79
  max_attempts = 3
@@ -117,7 +113,7 @@ def transcribe(audio, history_type):
117
 
118
  #Define Gradio Interface
119
  my_inputs = [
120
- gr.Audio(sources=["microphone"], type="filepath"),
121
  gr.Radio(["History","H+P","Impression/Plan","Full Visit","Handover","Psych","EMS","Meds Only"], show_label=False),
122
  ]
123
 
 
37
  messages = [{"role": "system", "content": role}]
38
 
39
  ######################## Read audio file, wait as necessary if not written
40
+ max_attempts = 1
41
  attempt = 0
42
  audio_data = None
43
  samplerate = None
 
56
  return # Terminate the function or raise an exception if the file could not be opened
57
 
58
 
59
+ ########## Cast as float 32, normalize
60
+ #audio_data = audio_data.astype("float32")
61
+ #audio_data = (audio_data * 32767).astype("int16")
 
 
 
62
  #audio_data = audio_data.mean(axis=1)
63
+
64
+ ###################Code to convert .wav to .mp3 (if neccesary)
65
  sf.write("Audio_Files/test.wav", audio_data, samplerate, subtype='PCM_16')
 
 
 
66
  sound = AudioSegment.from_wav("Audio_Files/test.wav")
67
  sound.export("Audio_Files/test.mp3", format="mp3")
 
 
 
68
 
69
+ sf.write("Audio_Files/test.mp3", audio_data, samplerate)
70
+
71
+
72
+ ################ Send file to Whisper for Transcription
73
  audio_file = open("Audio_Files/test.mp3", "rb")
74
 
75
  max_attempts = 3
 
113
 
114
  #Define Gradio Interface
115
  my_inputs = [
116
+ gr.Audio(sources=["microphone"], type="filepath",format="mp3"),
117
  gr.Radio(["History","H+P","Impression/Plan","Full Visit","Handover","Psych","EMS","Meds Only"], show_label=False),
118
  ]
119