File size: 1,764 Bytes
6c2e817
c6fe4cf
6c2e817
c6fe4cf
6c2e817
 
 
c6fe4cf
 
6c2e817
c6fe4cf
6c2e817
c6fe4cf
6c2e817
c6fe4cf
6c2e817
 
 
c6fe4cf
6c2e817
 
 
 
 
 
 
bb48ecb
c6fe4cf
 
 
 
 
 
 
 
 
 
 
 
6c2e817
 
 
 
 
 
aacfb92
c6fe4cf
6c2e817
 
 
 
 
 
 
 
c6fe4cf
6c2e817
 
aacfb92
 
 
c6fe4cf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import tempfile
import os
from fastapi import FastAPI, HTTPException, UploadFile, File, Form
from fastapi.responses import FileResponse
from pathlib import Path
import time

# Importer KokoClone depuis le package installé
from kokoclone import KokoClone

print("🚀 Initialisation de KokoClone...")
cloner = KokoClone()
print("✅ KokoClone prêt")

app = FastAPI(title="KokoClone API")

@app.get("/")
async def root():
    return {"status": "ok", "model": "KokoClone"}

@app.post("/clone")
async def clone_voice(
    text: str = Form(...),
    lang: str = Form(...),
    audio_file: UploadFile = File(...)
):
    try:
        # Sauvegarde du fichier audio de référence
        with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_ref:
            content = await audio_file.read()
            tmp_ref.write(content)
            ref_path = tmp_ref.name

        # Chemin de sortie
        output_filename = f"output_{int(time.time())}.wav"
        output_path = Path("/app/tmp") / output_filename
        output_path.parent.mkdir(parents=True, exist_ok=True)

        # Génération
        cloner.generate(
            text=text,
            lang=lang,
            reference_audio=ref_path,
            output_path=str(output_path)
        )

        # Nettoyage
        os.unlink(ref_path)

        return FileResponse(
            path=str(output_path),
            media_type="audio/wav",
            filename=output_filename
        )
    except Exception as e:
        if 'ref_path' in locals() and os.path.exists(ref_path):
            os.unlink(ref_path)
        raise HTTPException(status_code=500, detail=str(e))

@app.get("/voices")
async def list_voices():
    return {"languages": ["fr", "en", "es", "it", "ja", "zh", "hi", "pt"]}