kumararvindibs
commited on
Commit
•
2734ce5
1
Parent(s):
1f790f5
Update handler.py
Browse files- handler.py +24 -2
handler.py
CHANGED
@@ -4,7 +4,7 @@ import torch
|
|
4 |
import soundfile as sf
|
5 |
from transformers import AutoTokenizer, AutoModelForTextToWaveform
|
6 |
import cloudinary.uploader
|
7 |
-
|
8 |
# Configure logging
|
9 |
logging.basicConfig(level=logging.DEBUG)
|
10 |
# Configure logging
|
@@ -18,6 +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 |
def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
|
22 |
# Prepare the payload with input data
|
23 |
logging.warning(f"------input_data-- {str(data)}")
|
@@ -33,7 +34,7 @@ class EndpointHandler():
|
|
33 |
# Save the audio to a file
|
34 |
sf.write("StoryAudio.wav", outputs["waveform"][0].numpy(), self.model.config.sampling_rate)
|
35 |
uploadGraphFile("StoryAudio.wav")
|
36 |
-
|
37 |
#return 'StoryAudio.wav'
|
38 |
# Check if the request was successful
|
39 |
|
@@ -47,3 +48,24 @@ def uploadGraphFile(fileName):
|
|
47 |
# Upload a file to Cloudinary
|
48 |
result = cloudinary.uploader.upload(fileName, folder="poc-graph", resource_type="raw")
|
49 |
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
import soundfile as sf
|
5 |
from transformers import AutoTokenizer, AutoModelForTextToWaveform
|
6 |
import cloudinary.uploader
|
7 |
+
|
8 |
# Configure logging
|
9 |
logging.basicConfig(level=logging.DEBUG)
|
10 |
# Configure logging
|
|
|
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 |
+
main()
|
38 |
#return 'StoryAudio.wav'
|
39 |
# Check if the request was successful
|
40 |
|
|
|
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)
|