TenzinGayche commited on
Commit
37e5267
1 Parent(s): 049c36a

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +10 -8
handler.py CHANGED
@@ -1,4 +1,4 @@
1
- from typing import Dict
2
  import librosa
3
  import numpy as np
4
  import torch
@@ -52,14 +52,16 @@ class EndpointHandler():
52
  self.vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
53
 
54
 
55
- def __call__(self, data: Dict[str]) -> Dict[str, str]:
56
- """
 
57
  Args:
58
- data (:obj:):
59
- includes the deserialized audio file as bytes
60
- Return:
61
- A :obj:`dict`:. base64 encoded image
62
  """
 
63
  # process input
64
 
65
  if len(text.strip()) == 0:
@@ -75,4 +77,4 @@ class EndpointHandler():
75
  speaker_embedding = torch.tensor(speaker_embedding)
76
  speech = self.model.generate_speech(input_ids.to('cuda'), speaker_embedding.to('cuda'), vocoder=vocoder.to('cuda'))
77
  speech = nr.reduce_noise(y=speech.to('cpu'), sr=16000)
78
- return (16000, speech)
 
1
+ from typing import Dict, Any
2
  import librosa
3
  import numpy as np
4
  import torch
 
52
  self.vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
53
 
54
 
55
+ def __call__(self, data: Dict[str, Any]) -> bytes:
56
+ """_summary_
57
+
58
  Args:
59
+ data (Dict[str, Any]): _description_
60
+
61
+ Returns:
62
+ bytes: _description_
63
  """
64
+
65
  # process input
66
 
67
  if len(text.strip()) == 0:
 
77
  speaker_embedding = torch.tensor(speaker_embedding)
78
  speech = self.model.generate_speech(input_ids.to('cuda'), speaker_embedding.to('cuda'), vocoder=vocoder.to('cuda'))
79
  speech = nr.reduce_noise(y=speech.to('cpu'), sr=16000)
80
+ return speech.tobytes()