Update handler.py
Browse files- handler.py +7 -15
handler.py
CHANGED
@@ -11,7 +11,9 @@ logging.basicConfig(level=logging.ERROR)
|
|
11 |
# Configure logging
|
12 |
logging.basicConfig(level=logging.WARNING)
|
13 |
|
14 |
-
import
|
|
|
|
|
15 |
|
16 |
class EndpointHandler():
|
17 |
def __init__(self, path=""):
|
@@ -32,21 +34,11 @@ class EndpointHandler():
|
|
32 |
|
33 |
# Save the audio to a file
|
34 |
sf.write("StoryAudio.wav", outputs["waveform"][0].numpy(), self.model.config.sampling_rate)
|
35 |
-
|
36 |
-
pygame.mixer.init()
|
37 |
-
pygame.mixer.music.load("StoryAudio.wav")
|
38 |
-
pygame.mixer.music.play()
|
39 |
-
#return 'StoryAudio.wav'
|
40 |
-
#return {"audio_file_path": 'StoryAudio.wav'}
|
41 |
-
# with open("StoryAudio.wav", "rb") as f:
|
42 |
-
# audio_content = f.read()
|
43 |
-
|
44 |
-
# # Set the response content type
|
45 |
-
# response_headers = {"Content-Type": "audio/wav"}
|
46 |
-
|
47 |
-
# Return the binary content of the audio file along with the response headers
|
48 |
-
#return send_file("StoryAudio.wav", mimetype="audio/wav", as_attachment=True)
|
49 |
|
|
|
|
|
|
|
50 |
# Check if the request was successful
|
51 |
|
52 |
|
|
|
11 |
# Configure logging
|
12 |
logging.basicConfig(level=logging.WARNING)
|
13 |
|
14 |
+
from pydub import AudioSegment
|
15 |
+
from pydub.playback import play
|
16 |
+
|
17 |
|
18 |
class EndpointHandler():
|
19 |
def __init__(self, path=""):
|
|
|
34 |
|
35 |
# Save the audio to a file
|
36 |
sf.write("StoryAudio.wav", outputs["waveform"][0].numpy(), self.model.config.sampling_rate)
|
37 |
+
audio = AudioSegment.from_wav("StoryAudio.wav")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
+
# Play the audio file
|
40 |
+
play(audio)
|
41 |
+
return 'StoryAudio.wav'
|
42 |
# Check if the request was successful
|
43 |
|
44 |
|