feat: phonon and piper folders
Add phonon setup, currently has a main.py able to be run and test manito voice. Add piper folder and setup, not tested yet
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import ptts
|
||||
import sounddevice as sd
|
||||
import numpy as np
|
||||
import huggingface_hub as hf
|
||||
|
||||
|
||||
def main():
|
||||
print("Cargando el modelo Phonon TTS...")
|
||||
|
||||
# Inicializamos el modelo multilingue que incluye soporte para español.
|
||||
# Nota: Si prefieres no usar el login de Hugging Face y hacer una prueba rapida,
|
||||
# puedes cambiar el id a "hf://gradium/phonon-31m-en" y lang="en" (licencia Apache 2.0).
|
||||
tts = ptts.TTS(model="hf://gradium/phonon-40m-es", lang="es")
|
||||
tts.add_voice("MiVoz", "C:\\Users\\alcar\\Downloads\\TTS\\Phonon-40M-es\\x6lttij74JUPawTc.ba7a5a45@300.safetensors")
|
||||
|
||||
return tts
|
||||
|
||||
tts=main()
|
||||
|
||||
while True :
|
||||
|
||||
texto_prueba = input("Escribe el texto que quieres convertir a voz: ")
|
||||
|
||||
# 1. Guardar el resultado en un archivo WAV
|
||||
archivo_salida = "audio_clonado.wav"
|
||||
print(f"\nGenerando y guardando audio en {archivo_salida}...")
|
||||
|
||||
# Opcionalmente, puedes pasar el parametro voice="NombreVoz" si tienes voces descargadas.
|
||||
# Sin este parametro, usara la voz por defecto del modelo.
|
||||
tts.save("audio_clonado.wav", texto_prueba, voice="MiVoz")
|
||||
print("Archivo WAV guardado exitosamente.")
|
||||
|
||||
# 2. Streaming en tiempo real (reproduccion simultanea a la generacion)
|
||||
print("\nIniciando streaming de audio por los altavoces...")
|
||||
|
||||
# tts.stream devuelve un generador de chunks de audio
|
||||
with tts.stream(texto_prueba, voice="MiVoz") as audio_generator:
|
||||
# Abrimos el stream fisico de audio usando la frecuencia de muestreo nativa del modelo (usualmente 24 kHz)
|
||||
with sd.OutputStream(samplerate=audio_generator.sample_rate, channels=1, dtype='float32') as stream_salida:
|
||||
for pcm_chunk in audio_generator:
|
||||
# Phonon entrega float32, lo preparamos como un array de numpy en 2D (frames, channels)
|
||||
# para asegurar la maxima compatibilidad con sounddevice
|
||||
datos_audio = np.array(pcm_chunk, dtype=np.float32).reshape(-1, 1)
|
||||
|
||||
# Escribimos el chunk directamente a la tarjeta de sonido
|
||||
stream_salida.write(datos_audio)
|
||||
|
||||
print("\nStreaming finalizado correctamente.")
|
||||
Reference in New Issue
Block a user