Spaces:
Sleeping
Sleeping
File size: 576 Bytes
4f0a2be e37d2df 4f0a2be a24b1a1 4f0a2be 01d4407 4f0a2be e37d2df aead49d c567be8 e37d2df a24b1a1 e37d2df c567be8 e37d2df |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
from fastapi import FastAPI
from fastapi.responses import StreamingResponse
from transformers import pipeline
import io
import soundfile as sf
app = FastAPI()
# Load TTS pipeline
tts = pipeline("text-to-speech", model="suno/bark-small")
@app.get("/speak")
def speak(text: str):
# Generate speech (numpy float32 array)
output = tts(text)
audio = output["audio"]
# Write WAV to in-memory buffer
buf = io.BytesIO()
sf.write(buf, audio, 24000, format="WAV") # Bark uses 24kHz
buf.seek(0)
return StreamingResponse(buf, media_type="audio/wav")
|