Athspi commited on
Commit
4f33135
·
verified ·
1 Parent(s): 700dfd4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -223,7 +223,7 @@ def detect_voice_activity(audio_file, threshold=0.02):
223
  if len(data.shape) > 1:
224
  data = np.mean(data, axis=1)
225
 
226
- # Normalize the audio data
227
  if data.dtype != np.float32:
228
  data = data.astype(np.float32) / np.iinfo(data.dtype).max
229
 
@@ -248,9 +248,12 @@ def detect_voice_activity(audio_file, threshold=0.02):
248
  for segment in voice_segments:
249
  trimmed_audio = np.concatenate((trimmed_audio, data[segment[0]:segment[1]]))
250
 
 
 
 
251
  # Export the trimmed audio
252
  output_path = "voice_trimmed_audio.wav"
253
- wavfile.write(output_path, sample_rate, trimmed_audio)
254
 
255
  # Clean up the converted WAV file
256
  os.remove(wav_path)
 
223
  if len(data.shape) > 1:
224
  data = np.mean(data, axis=1)
225
 
226
+ # Normalize the audio data to the range [-1, 1]
227
  if data.dtype != np.float32:
228
  data = data.astype(np.float32) / np.iinfo(data.dtype).max
229
 
 
248
  for segment in voice_segments:
249
  trimmed_audio = np.concatenate((trimmed_audio, data[segment[0]:segment[1]]))
250
 
251
+ # Convert the trimmed audio back to 16-bit integer format
252
+ trimmed_audio_int16 = np.int16(trimmed_audio * 32767)
253
+
254
  # Export the trimmed audio
255
  output_path = "voice_trimmed_audio.wav"
256
+ wavfile.write(output_path, sample_rate, trimmed_audio_int16)
257
 
258
  # Clean up the converted WAV file
259
  os.remove(wav_path)