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