Add gitignor
This commit is contained in:
57
scripts/register_voice.py
Normal file
57
scripts/register_voice.py
Normal file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Script pour enregistrer une voix personnalisée via Voxtral TTS (Phase 2).
|
||||
|
||||
Usage :
|
||||
python scripts/register_voice.py --name "Ma voix" --audio path/to/sample.mp3
|
||||
|
||||
L'identifiant de la voix créée sera affiché et pourra être ajouté à .env :
|
||||
VOICE_ID=<id_retourné>
|
||||
"""
|
||||
import argparse
|
||||
import base64
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Permettre l'import depuis la racine du projet
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
|
||||
from mistralai.client import Mistral
|
||||
from assistant import config
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description="Enregistrer une voix Voxtral")
|
||||
parser.add_argument("--name", required=True, help="Nom de la voix")
|
||||
parser.add_argument("--audio", required=True, help="Chemin vers le fichier audio (mp3/wav)")
|
||||
parser.add_argument("--gender", default=None, help="Genre : male ou female")
|
||||
parser.add_argument("--language", default="fr", help="Langue principale (ex: fr, en)")
|
||||
args = parser.parse_args()
|
||||
|
||||
audio_path = Path(args.audio)
|
||||
if not audio_path.exists():
|
||||
print(f"Erreur : fichier introuvable : {audio_path}")
|
||||
sys.exit(1)
|
||||
|
||||
sample_audio_b64 = base64.b64encode(audio_path.read_bytes()).decode()
|
||||
|
||||
client = Mistral(api_key=config.MISTRAL_API_KEY)
|
||||
|
||||
print(f"Enregistrement de la voix '{args.name}'...")
|
||||
voice = client.audio.voices.create(
|
||||
name=args.name,
|
||||
sample_audio=sample_audio_b64,
|
||||
sample_filename=audio_path.name,
|
||||
languages=[args.language],
|
||||
**({"gender": args.gender} if args.gender else {}),
|
||||
)
|
||||
|
||||
print(f"\n✅ Voix créée avec succès !")
|
||||
print(f" ID : {voice.id}")
|
||||
print(f" Nom : {voice.name}")
|
||||
print(f"\nAjoute dans ton fichier .env :")
|
||||
print(f" VOICE_ID={voice.id}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user