Spaces:
Runtime error
Runtime error
| import os | |
| import sys | |
| import requests | |
| import soundfile as sf | |
| # adiciona a pasta src no path para importar o F5-TTS | |
| sys.path.append("/usr/local/lib/python3.10/site-packages/f5_tts") # ajuste se necessário | |
| sys.path.append("src") # caso esteja no repo clonado | |
| from f5_tts.inference import inference | |
| # URLs dos arquivos | |
| MODEL_URL = "https://huggingface.co/firstpixel/F5-TTS-pt-br/resolve/main/pt-br/model_last.safetensors" | |
| CONFIG_URL = "https://raw.githubusercontent.com/SWivid/F5-TTS/main/src/f5_tts/configs/F5TTS_Base.yaml" | |
| VOCAB_URL = "https://huggingface.co/SWivid/F5-TTS/raw/main/F5TTS_Base/vocab.txt" | |
| # Pastas locais | |
| os.makedirs("model", exist_ok=True) | |
| os.makedirs("config", exist_ok=True) | |
| os.makedirs("vocoder", exist_ok=True) | |
| MODEL_FILE = "model/model_last.safetensors" | |
| CONFIG_FILE = "config/config.yaml" | |
| VOCAB_FILE = "vocoder/vocab.txt" | |
| # Função para baixar arquivos | |
| def download_file(url, path): | |
| if not os.path.exists(path): | |
| print(f"⬇️ Baixando {url} ...") | |
| r = requests.get(url) | |
| r.raise_for_status() | |
| with open(path, "wb") as f: | |
| f.write(r.content) | |
| print(f"✅ Salvo em {path}") | |
| else: | |
| print(f"✔️ Já existe: {path}") | |
| # Baixa os arquivos necessários | |
| download_file(MODEL_URL, MODEL_FILE) | |
| download_file(CONFIG_URL, CONFIG_FILE) | |
| download_file(VOCAB_URL, VOCAB_FILE) | |
| # Texto de teste | |
| texto = "Olá, seja bem-vindo ao teste do F5-TTS em português." | |
| # Faz inferência | |
| print("🎙️ Gerando áudio...") | |
| wav = inference( | |
| text=texto, | |
| model_path=MODEL_FILE, | |
| config_path=CONFIG_FILE, | |
| vocab_path=VOCAB_FILE | |
| ) | |
| # Salva o resultado | |
| sf.write("output.wav", wav, 24000) | |
| print("✅ Áudio salvo em output.wav") | |