Spaces:
Sleeping
Sleeping
conversation
Browse files
app.py
CHANGED
|
@@ -6,29 +6,35 @@ os.system('python -m unidic download')
|
|
| 6 |
# print("Make sure you've downloaded unidic (python -m unidic download) for this WebUI to work.")
|
| 7 |
from melo.api import TTS
|
| 8 |
import tempfile
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
@spaces.GPU
|
| 11 |
def synthesize(conversation_text, speed, progress=gr.Progress()):
|
| 12 |
-
speed = 1.0
|
| 13 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 14 |
models = {
|
| 15 |
'EN': TTS(language='EN', device=device),
|
| 16 |
}
|
| 17 |
speakers = ['EN-US', 'EN-Default']
|
| 18 |
-
final_audio = io.BytesIO()
|
| 19 |
|
|
|
|
| 20 |
conversation = json.loads(conversation_text)
|
| 21 |
for i, turn in enumerate(conversation["conversation"]):
|
| 22 |
-
bio = io.BytesIO()
|
| 23 |
-
text = turn["text"]
|
| 24 |
-
|
| 25 |
-
speaker = speakers[i % 2]
|
| 26 |
speaker_id = models['EN'].hps.data.spk2id[speaker]
|
| 27 |
-
models['EN'].tts_to_file(text, speaker_id, bio, speed=speed, pbar=progress.tqdm, format='wav')
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
return final_audio.getvalue()
|
| 31 |
-
|
| 32 |
with gr.Blocks() as demo:
|
| 33 |
gr.Markdown('# Turn Any Article into Podcast')
|
| 34 |
gr.Markdown('## Easily convert articles from URLs into listenable audio Podcast.')
|
|
|
|
| 6 |
# print("Make sure you've downloaded unidic (python -m unidic download) for this WebUI to work.")
|
| 7 |
from melo.api import TTS
|
| 8 |
import tempfile
|
| 9 |
+
import wave
|
| 10 |
+
from pydub import AudioSegment
|
| 11 |
+
|
| 12 |
|
| 13 |
@spaces.GPU
|
| 14 |
def synthesize(conversation_text, speed, progress=gr.Progress()):
|
|
|
|
| 15 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 16 |
models = {
|
| 17 |
'EN': TTS(language='EN', device=device),
|
| 18 |
}
|
| 19 |
speakers = ['EN-US', 'EN-Default']
|
|
|
|
| 20 |
|
| 21 |
+
combined_audio = AudioSegment.empty()
|
| 22 |
conversation = json.loads(conversation_text)
|
| 23 |
for i, turn in enumerate(conversation["conversation"]):
|
| 24 |
+
bio = io.BytesIO()
|
| 25 |
+
text = turn["text"]
|
| 26 |
+
speaker = speakers[i % 2]
|
|
|
|
| 27 |
speaker_id = models['EN'].hps.data.spk2id[speaker]
|
| 28 |
+
models['EN'].tts_to_file(text, speaker_id, bio, speed=speed, pbar=progress.tqdm, format='wav')
|
| 29 |
+
bio.seek(0)
|
| 30 |
+
audio_segment = AudioSegment.from_file(bio, format="wav")
|
| 31 |
+
combined_audio += audio_segment
|
| 32 |
+
|
| 33 |
+
final_audio_path = 'final.mp3'
|
| 34 |
+
combined_audio.export(final_audio_path, format='mp3')
|
| 35 |
+
return final_audio_path
|
| 36 |
+
|
| 37 |
|
|
|
|
|
|
|
| 38 |
with gr.Blocks() as demo:
|
| 39 |
gr.Markdown('# Turn Any Article into Podcast')
|
| 40 |
gr.Markdown('## Easily convert articles from URLs into listenable audio Podcast.')
|