Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import requests
|
|
3 |
import urllib.request
|
4 |
from pydub import AudioSegment
|
5 |
import numpy as np
|
|
|
6 |
|
7 |
def function1(prompt):
|
8 |
response = requests.post("https://tommy24-testing3.hf.space/run/predict", json={
|
@@ -17,9 +18,22 @@ def function1(prompt):
|
|
17 |
]
|
18 |
}).json()
|
19 |
data = response["data"][0]["name"]
|
20 |
-
data = "https://matthijs-speecht5-tts-demo.hf.space/file="+data
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import urllib.request
|
4 |
from pydub import AudioSegment
|
5 |
import numpy as np
|
6 |
+
import os
|
7 |
|
8 |
def function1(prompt):
|
9 |
response = requests.post("https://tommy24-testing3.hf.space/run/predict", json={
|
|
|
18 |
]
|
19 |
}).json()
|
20 |
data = response["data"][0]["name"]
|
21 |
+
data = "https://matthijs-speecht5-tts-demo.hf.space/file=" + data
|
22 |
+
|
23 |
+
# Download the audio file and save it in WAV format
|
24 |
+
file_name, headers = urllib.request.urlretrieve(data, "speech.wav")
|
25 |
+
|
26 |
+
# Load the audio file using pydub
|
27 |
+
sound = AudioSegment.from_wav("speech.wav")
|
28 |
+
|
29 |
+
# Set the path and file name for the converted MP3 file
|
30 |
+
mp3_file = "speech.mp3"
|
31 |
+
|
32 |
+
# Export the audio in MP3 format
|
33 |
+
sound.export(mp3_file, format="mp3")
|
34 |
+
|
35 |
+
# Delete the WAV file
|
36 |
+
os.remove("speech.wav")
|
37 |
+
|
38 |
+
# Return the path to the MP3 file
|
39 |
+
return os.path.abspath(mp3_file)
|