File size: 740 Bytes
b0184f5 dbf58fe b0184f5 dbf58fe b0184f5 dbf58fe b0184f5 dbf58fe b0184f5 dbf58fe b0184f5 dbf58fe |
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 |
from bark import generate_audio, preload_models
import torch
import numpy as np
import scipy
import io
import base64
class EndpointHandler:
def __init__(self, path=""):
preload_models()
def __call__(self, data):
text = data.get("inputs", "")
if not text.strip():
return {"error": "No input text provided."}
audio_array = generate_audio(text, history_prompt="v2/ru_speaker_0")
byte_io = io.BytesIO()
scipy.io.wavfile.write(byte_io, rate=24000, data=audio_array)
byte_io.seek(0)
audio_base64 = base64.b64encode(byte_io.read()).decode("utf-8")
return {
"audio_base64": audio_base64,
"content_type": "audio/wav"
}
|