rime: pass aiohttp session to constructor
This commit is contained in:
@@ -17,6 +17,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
- `RimeHttpTTSService` needs an `aiohttp.ClientSession` to be passed to the
|
||||||
|
constructor as all the other HTTP-based services.
|
||||||
|
|
||||||
|
- `RimeHttpTTSService` doesn't use a default voice anymore.
|
||||||
|
|
||||||
- `DeepgramSTTService` now uses the new `nova-3` model by default. If you want
|
- `DeepgramSTTService` now uses the new `nova-3` model by default. If you want
|
||||||
to use the previous model you can pass `LiveOptions(model="nova-2-general")`.
|
to use the previous model you can pass `LiveOptions(model="nova-2-general")`.
|
||||||
(see https://deepgram.com/learn/introducing-nova-3-speech-to-text-api)
|
(see https://deepgram.com/learn/introducing-nova-3-speech-to-text-api)
|
||||||
|
|||||||
@@ -345,7 +345,8 @@ class RimeHttpTTSService(TTSService):
|
|||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
api_key: str,
|
api_key: str,
|
||||||
voice_id: str = "eva",
|
voice_id: str,
|
||||||
|
aiohttp_session: aiohttp.ClientSession,
|
||||||
model: str = "mistv2",
|
model: str = "mistv2",
|
||||||
sample_rate: Optional[int] = None,
|
sample_rate: Optional[int] = None,
|
||||||
params: InputParams = InputParams(),
|
params: InputParams = InputParams(),
|
||||||
@@ -354,6 +355,7 @@ class RimeHttpTTSService(TTSService):
|
|||||||
super().__init__(sample_rate=sample_rate, **kwargs)
|
super().__init__(sample_rate=sample_rate, **kwargs)
|
||||||
|
|
||||||
self._api_key = api_key
|
self._api_key = api_key
|
||||||
|
self._session = aiohttp_session
|
||||||
self._base_url = "https://users.rime.ai/v1/rime-tts"
|
self._base_url = "https://users.rime.ai/v1/rime-tts"
|
||||||
self._settings = {
|
self._settings = {
|
||||||
"speedAlpha": params.speed_alpha,
|
"speedAlpha": params.speed_alpha,
|
||||||
@@ -388,30 +390,27 @@ class RimeHttpTTSService(TTSService):
|
|||||||
try:
|
try:
|
||||||
await self.start_ttfb_metrics()
|
await self.start_ttfb_metrics()
|
||||||
|
|
||||||
async with aiohttp.ClientSession() as session:
|
async with self._session.post(
|
||||||
async with session.post(self._base_url, json=payload, headers=headers) as response:
|
self._base_url, json=payload, headers=headers
|
||||||
if response.status != 200:
|
) as response:
|
||||||
error_message = f"Rime TTS error: HTTP {response.status}"
|
if response.status != 200:
|
||||||
logger.error(error_message)
|
error_message = f"Rime TTS error: HTTP {response.status}"
|
||||||
yield ErrorFrame(error=error_message)
|
logger.error(error_message)
|
||||||
return
|
yield ErrorFrame(error=error_message)
|
||||||
|
return
|
||||||
|
|
||||||
await self.start_tts_usage_metrics(text)
|
await self.start_tts_usage_metrics(text)
|
||||||
|
|
||||||
yield TTSStartedFrame()
|
yield TTSStartedFrame()
|
||||||
|
|
||||||
# Process the streaming response
|
# Process the streaming response
|
||||||
chunk_size = 8192
|
chunk_size = 8192
|
||||||
first_chunk = True
|
|
||||||
|
|
||||||
async for chunk in response.content.iter_chunked(chunk_size):
|
async for chunk in response.content.iter_chunked(chunk_size):
|
||||||
if first_chunk:
|
if chunk:
|
||||||
await self.stop_ttfb_metrics()
|
await self.stop_ttfb_metrics()
|
||||||
first_chunk = False
|
frame = TTSAudioRawFrame(chunk, self.sample_rate, 1)
|
||||||
|
yield frame
|
||||||
if chunk:
|
|
||||||
frame = TTSAudioRawFrame(chunk, self.sample_rate, 1)
|
|
||||||
yield frame
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(f"Error generating TTS: {e}")
|
logger.exception(f"Error generating TTS: {e}")
|
||||||
yield ErrorFrame(error=f"Rime TTS error: {str(e)}")
|
yield ErrorFrame(error=f"Rime TTS error: {str(e)}")
|
||||||
|
|||||||
Reference in New Issue
Block a user