AshDavid12 commited on
Commit
b157f40
·
1 Parent(s): bbca80e

use wave.open

Browse files
Files changed (1) hide show
  1. infer.py +10 -2
infer.py CHANGED
@@ -1,5 +1,6 @@
1
  import base64
2
  import os
 
3
 
4
  import faster_whisper
5
  import tempfile
@@ -209,8 +210,15 @@ async def websocket_transcribe(websocket: WebSocket):
209
  # Create a new file for the chunk
210
  chunk_filename = os.path.join(output_directory, f"audio_chunk_{chunk_counter}.wav")
211
  chunk_counter += 1
212
- with open(chunk_filename, 'wb') as audio_file:
213
- audio_file.write(audio_chunk)
 
 
 
 
 
 
 
214
 
215
  # Write audio chunk to file and accumulate size and time
216
  temp_audio_file.write(audio_chunk)
 
1
  import base64
2
  import os
3
+ import wave
4
 
5
  import faster_whisper
6
  import tempfile
 
210
  # Create a new file for the chunk
211
  chunk_filename = os.path.join(output_directory, f"audio_chunk_{chunk_counter}.wav")
212
  chunk_counter += 1
213
+
214
+ with wave.open(chunk_filename, 'wb') as wav_file:
215
+ wav_file.setnchannels(1) # Mono channel
216
+ wav_file.setsampwidth(2) # 2 bytes per sample (16-bit audio)
217
+ wav_file.setframerate(16000) # 16 kHz sample rate
218
+ wav_file.writeframes(audio_chunk)
219
+
220
+ # with open(chunk_filename, 'wb') as audio_file:
221
+ # audio_file.write(audio_chunk)
222
 
223
  # Write audio chunk to file and accumulate size and time
224
  temp_audio_file.write(audio_chunk)