feat(solaris): add init to agent

This commit is contained in:
h
2025-07-02 10:02:33 +03:00
parent 7a2f28b94e
commit 4bd0df4e5a
2 changed files with 7 additions and 7 deletions

View File

@@ -0,0 +1 @@
pass

View File

@@ -1,29 +1,28 @@
import io
from google import genai
from google.genai import types
from pydub import AudioSegment
from ..content_configs import TTS_CONTENT_CONFIG
class TTSAgent:
def __init__(self, api_key: str) -> None:
# код повторяется некрасиво
self.client = genai.Client(api_key=api_key).aio
async def generate(self, text: str):
response = await self.client.models.generate_content(
model="gemini-2.5-flash-preview-tts",
contents=text,
config=TTS_CONTENT_CONFIG
config=TTS_CONTENT_CONFIG,
)
data = response.candidates[0].content.parts[0].inline_data.data
pcm_io = io.BytesIO(data)
audio = AudioSegment(
pcm_io.read(),
sample_width=2,
frame_rate=24000,
channels=1
pcm_io.read(), sample_width=2, frame_rate=24000, channels=1
)
ogg_io = io.BytesIO()
audio.export(ogg_io, format="ogg", codec="libopus")
ogg_bytes = ogg_io.getvalue()
return ogg_bytes