fed8b2eed7
Backend release / release (push) Waiting to run
Bandit Security Scan / bandit_scan (push) Waiting to run
Build and push multi-arch DocsGPT Docker image / build (linux/amd64, ubuntu-latest, amd64) (push) Waiting to run
Build and push multi-arch DocsGPT Docker image / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Waiting to run
Build and push multi-arch DocsGPT Docker image / manifest (push) Blocked by required conditions
Build and push DocsGPT FE Docker image for development / build (linux/amd64, ubuntu-latest, amd64) (push) Waiting to run
Build and push DocsGPT FE Docker image for development / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Waiting to run
Build and push DocsGPT FE Docker image for development / manifest (push) Blocked by required conditions
Python linting / ruff (push) Waiting to run
Run python tests with pytest / Run tests and count coverage (3.12) (push) Waiting to run
React Widget Build / build (push) Waiting to run
31 lines
891 B
Python
31 lines
891 B
Python
from io import BytesIO
|
|
import base64
|
|
from application.tts.base import BaseTTS
|
|
from application.core.settings import settings
|
|
|
|
|
|
class ElevenlabsTTS(BaseTTS):
|
|
def __init__(self):
|
|
from elevenlabs.client import ElevenLabs
|
|
|
|
self.client = ElevenLabs(
|
|
api_key=settings.ELEVENLABS_API_KEY,
|
|
)
|
|
|
|
|
|
def text_to_speech(self, text):
|
|
lang = "en"
|
|
audio = self.client.text_to_speech.convert(
|
|
voice_id="nPczCjzI2devNBz1zQrb",
|
|
model_id="eleven_multilingual_v2",
|
|
text=text,
|
|
output_format="mp3_44100_128"
|
|
)
|
|
audio_data = BytesIO()
|
|
for chunk in audio:
|
|
audio_data.write(chunk)
|
|
audio_bytes = audio_data.getvalue()
|
|
|
|
# Encode to base64
|
|
audio_base64 = base64.b64encode(audio_bytes).decode("utf-8")
|
|
return audio_base64, lang |