Spaces:
Sleeping
Sleeping
| 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") | |
| 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") | |