| import requests |
| from config import HUGGINGFACE_API_KEY |
|
|
| |
| BARK_MODEL_ID = "suno/bark" |
|
|
| def text_to_speech(text: str) -> bytes: |
| """ |
| Convert text to speech (audio bytes) using Hugging Face Bark model. |
| """ |
| url = f"https://api-inference.huggingface.co/models/{BARK_MODEL_ID}" |
|
|
| headers = { |
| "Authorization": f"Bearer {HUGGINGFACE_API_KEY}", |
| "Content-Type": "application/json" |
| } |
|
|
| payload = { |
| "inputs": text |
| } |
|
|
| response = requests.post(url, headers=headers, json=payload) |
|
|
| |
| if response.status_code != 200: |
| raise Exception(f"Bark API error: {response.text}") |
|
|
| return response.content |
|
|