Download app.py from Percy3822/TTS: direct link, hf CLI and curl.
- Browser
- Download file 917 Bytes
-
https://huggingface.co/spaces/Percy3822/TTS/resolve/main/app.py
- Command line
-
hf download hf://spaces/Percy3822/TTS/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Percy3822/TTS/resolve/main/app.py
917 Bytes
| import io, math, wave, uuid | |
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| from fastapi.responses import FileResponse | |
| app = FastAPI(title="TTS Space (stub)") | |
| class SpeakIn(BaseModel): | |
| text: str | |
| def _beep_wav(duration_s=0.4, sr=16000, freq=440): | |
| n = int(duration_s*sr) | |
| buf = bytearray() | |
| for i in range(n): | |
| val = int(32767*0.2*math.sin(2*math.pi*freq*i/sr)) | |
| buf += val.to_bytes(2, byteorder="little", signed=True) | |
| path = f"/tmp/{uuid.uuid4().hex}.wav" | |
| with wave.open(path, "wb") as w: | |
| w.setnchannels(1) | |
| w.setsampwidth(2) | |
| w.setframerate(sr) | |
| w.writeframes(buf) | |
| return path | |
| def speak(inp: SpeakIn): | |
| # Stub: ignore text, return a short beep so Brain can play audio. | |
| path = _beep_wav() | |
| return {"audio_path": path} | |
| def file(name: str): | |
| return FileResponse(f"/tmp/{name}") |