rafaaa2105 commited on
Commit
c1d27f0
·
verified ·
1 Parent(s): e9036e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -2
app.py CHANGED
@@ -6,6 +6,7 @@ import zipfile
6
  import tempfile
7
  import shutil
8
  from pydub import AudioSegment
 
9
 
10
  hf_token = os.getenv("HF_TOKEN")
11
 
@@ -32,14 +33,15 @@ def process_zip(zip_file):
32
 
33
  # Load audio file
34
  audio = AudioSegment.from_file(file_path)
35
- samples = audio.get_array_of_samples()
36
 
37
  # Convert to mono if stereo
38
  if audio.channels == 2:
39
- samples = samples[::2] # Take left channel
40
 
41
  # Convert to float32 numpy array
42
  waveform = torch.tensor(samples).float() / 32768.0 # Assuming 16-bit audio
 
43
 
44
  # Perform diarization
45
  diarization = pipeline({"waveform": waveform, "sample_rate": audio.frame_rate})
 
6
  import tempfile
7
  import shutil
8
  from pydub import AudioSegment
9
+ import numpy as np
10
 
11
  hf_token = os.getenv("HF_TOKEN")
12
 
 
33
 
34
  # Load audio file
35
  audio = AudioSegment.from_file(file_path)
36
+ samples = np.array(audio.get_array_of_samples())
37
 
38
  # Convert to mono if stereo
39
  if audio.channels == 2:
40
+ samples = samples.reshape((-1, 2)).mean(axis=1)
41
 
42
  # Convert to float32 numpy array
43
  waveform = torch.tensor(samples).float() / 32768.0 # Assuming 16-bit audio
44
+ waveform = waveform.unsqueeze(0) # Add channel dimension
45
 
46
  # Perform diarization
47
  diarization = pipeline({"waveform": waveform, "sample_rate": audio.frame_rate})