Skip to content

Commit

Permalink
fix meloTTS
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielchua committed Sep 30, 2024
1 parent 8fa13bc commit b9d657b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
4 changes: 4 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def generate_podcast(
raise gr.Error(
"The total content is too long. Please ensure the combined text from PDFs and URL is fewer than ~100,000 characters."
)


# Modify the system prompt based on the user input
modified_system_prompt = SYSTEM_PROMPT
Expand Down Expand Up @@ -156,6 +157,9 @@ def generate_podcast(
transcript += speaker + "\n\n"
total_characters += len(line.text)

if not use_advanced_audio:
LANGUAGE_MAPPING = MELO_TTS_LANGUAGE_MAPPING

# Get audio file path
audio_file_path = generate_podcast_audio(
line.text, line.speaker, LANGUAGE_MAPPING[language], use_advanced_audio
Expand Down
23 changes: 15 additions & 8 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import os
import requests
import time
from gradio_client import Client
from openai import OpenAI
from pydantic import ValidationError
Expand Down Expand Up @@ -102,11 +103,17 @@ def generate_podcast_audio(text: str, speaker: str, language: str, use_advanced_
speed = 1.1

# Generate audio
result = hf_client.predict(
text=text,
language=language,
speaker=accent,
speed=speed,
api_name="/synthesize",
)
return result
for attempt in range(3):
try:
result = hf_client.predict(
text=text,
language=language,
speaker=accent,
speed=speed,
api_name="/synthesize",
)
return result
except Exception as e:
if attempt == 2: # Last attempt
raise # Re-raise the last exception if all attempts fail
time.sleep(1) # Wait for 1 second before retrying

0 comments on commit b9d657b

Please sign in to comment.