Update handler.py
Browse files- handler.py +2 -24
handler.py
CHANGED
@@ -18,7 +18,7 @@ class EndpointHandler():
|
|
18 |
|
19 |
self.tokenizer = AutoTokenizer.from_pretrained("facebook/mms-tts-eng")
|
20 |
self.model= AutoModelForTextToWaveform.from_pretrained("facebook/mms-tts-eng")
|
21 |
-
|
22 |
def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
|
23 |
# Prepare the payload with input data
|
24 |
logging.warning(f"------input_data-- {str(data)}")
|
@@ -34,7 +34,6 @@ class EndpointHandler():
|
|
34 |
# Save the audio to a file
|
35 |
sf.write("StoryAudio.wav", outputs["waveform"][0].numpy(), self.model.config.sampling_rate)
|
36 |
uploadGraphFile("StoryAudio.wav")
|
37 |
-
main()
|
38 |
#return 'StoryAudio.wav'
|
39 |
# Check if the request was successful
|
40 |
|
@@ -47,25 +46,4 @@ def uploadGraphFile(fileName):
|
|
47 |
)
|
48 |
# Upload a file to Cloudinary
|
49 |
result = cloudinary.uploader.upload(fileName, folder="poc-graph", resource_type="raw")
|
50 |
-
return result
|
51 |
-
import pygame
|
52 |
-
import time
|
53 |
-
|
54 |
-
def play_audio(file_path):
|
55 |
-
pygame.init()
|
56 |
-
pygame.mixer.music.load(file_path)
|
57 |
-
pygame.mixer.music.play()
|
58 |
-
|
59 |
-
def stop_audio():
|
60 |
-
pygame.mixer.music.stop()
|
61 |
-
|
62 |
-
def main():
|
63 |
-
audio_file = "StoryAudio.wav"
|
64 |
-
play_audio(audio_file)
|
65 |
-
duration = pygame.mixer.Sound(audio_file).get_length()
|
66 |
-
start_time = time.time()
|
67 |
-
while pygame.mixer.music.get_busy():
|
68 |
-
current_time = time.time() - start_time
|
69 |
-
progress = current_time / duration * 100
|
70 |
-
print(f"Playback progress: {progress:.2f}%")
|
71 |
-
time.sleep(0.1)
|
|
|
18 |
|
19 |
self.tokenizer = AutoTokenizer.from_pretrained("facebook/mms-tts-eng")
|
20 |
self.model= AutoModelForTextToWaveform.from_pretrained("facebook/mms-tts-eng")
|
21 |
+
|
22 |
def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
|
23 |
# Prepare the payload with input data
|
24 |
logging.warning(f"------input_data-- {str(data)}")
|
|
|
34 |
# Save the audio to a file
|
35 |
sf.write("StoryAudio.wav", outputs["waveform"][0].numpy(), self.model.config.sampling_rate)
|
36 |
uploadGraphFile("StoryAudio.wav")
|
|
|
37 |
#return 'StoryAudio.wav'
|
38 |
# Check if the request was successful
|
39 |
|
|
|
46 |
)
|
47 |
# Upload a file to Cloudinary
|
48 |
result = cloudinary.uploader.upload(fileName, folder="poc-graph", resource_type="raw")
|
49 |
+
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|