feat(solaris): add init to agent
This commit is contained in:
1
src/bot/modules/solaris/agents/__init__.py
Normal file
1
src/bot/modules/solaris/agents/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
pass
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user