TenzinGayche commited on
Commit
a5deb0e
1 Parent(s): c3fc48f

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +1 -26
handler.py CHANGED
@@ -13,23 +13,7 @@ import re
13
  import requests
14
  import os
15
  from pydub import AudioSegment
16
- def increase_volume_without_distortion(audio_data, sample_rate, target_dBFS):
17
- # Create an AudioSegment from raw audio data
18
- audio_segment = AudioSegment(
19
- audio_data.tobytes(),
20
- frame_rate=sample_rate,
21
- sample_width=audio_data.dtype.itemsize,
22
- channels=1 # or 2 for stereo
23
- )
24
-
25
- # Normalize the audio level
26
- change_in_dBFS = target_dBFS - audio_segment.dBFS
27
- normalized_audio = audio_segment.apply_gain(change_in_dBFS)
28
-
29
- # Convert the AudioSegment back to a numpy array
30
- normalized_audio_data = np.array(normalized_audio.get_array_of_samples()).astype(np.int16)
31
-
32
- return normalized_audio_data
33
  converter = pyewts.pyewts()
34
  def download_file(url, destination):
35
  response = requests.get(url)
@@ -102,15 +86,6 @@ class EndpointHandler():
102
  speaker_embedding = torch.tensor(speaker_embedding)
103
  speech = self.model.generate_speech(input_ids.to('cuda'), speaker_embedding.to('cuda'), vocoder=self.vocoder.to('cuda'))
104
  speech = nr.reduce_noise(y=speech.to('cpu'), sr=16000)
105
- if isinstance(speech, torch.Tensor):
106
-
107
-
108
- speech = speech.numpy()
109
-
110
- # Increase volume without distortion
111
- target_dBFS = -20.0 # Adjust the value according to your requirement
112
- speech = increase_volume_without_distortion(speech, 16000, target_dBFS)
113
-
114
  # Create a unique temporary WAV file
115
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as temp_wav_file:
116
  temp_wav_path = temp_wav_file.name
 
13
  import requests
14
  import os
15
  from pydub import AudioSegment
16
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  converter = pyewts.pyewts()
18
  def download_file(url, destination):
19
  response = requests.get(url)
 
86
  speaker_embedding = torch.tensor(speaker_embedding)
87
  speech = self.model.generate_speech(input_ids.to('cuda'), speaker_embedding.to('cuda'), vocoder=self.vocoder.to('cuda'))
88
  speech = nr.reduce_noise(y=speech.to('cpu'), sr=16000)
 
 
 
 
 
 
 
 
 
89
  # Create a unique temporary WAV file
90
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as temp_wav_file:
91
  temp_wav_path = temp_wav_file.name