Merge pull request #1447 from nicougou/feat/support_tts_instruct
feature/support instructions in OpenAITTSService
This commit is contained in:
@@ -21,6 +21,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
- ElevenLabs TTS services now support a sample rate of 8000.
|
- ElevenLabs TTS services now support a sample rate of 8000.
|
||||||
|
|
||||||
|
- Added support for `instructions` in `OpenAITTSService`
|
||||||
|
|
||||||
|
- Added support for `base_url` in `OpenAIImageGenService` and `OpenAITTSService`
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Fixed an issue in Daily involving switching virtual devices, by bumping the
|
- Fixed an issue in Daily involving switching virtual devices, by bumping the
|
||||||
|
|||||||
@@ -391,6 +391,7 @@ class OpenAIImageGenService(ImageGenService):
|
|||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
api_key: str,
|
api_key: str,
|
||||||
|
base_url: Optional[str] = None,
|
||||||
aiohttp_session: aiohttp.ClientSession,
|
aiohttp_session: aiohttp.ClientSession,
|
||||||
image_size: Literal["256x256", "512x512", "1024x1024", "1792x1024", "1024x1792"],
|
image_size: Literal["256x256", "512x512", "1024x1024", "1792x1024", "1024x1792"],
|
||||||
model: str = "dall-e-3",
|
model: str = "dall-e-3",
|
||||||
@@ -398,7 +399,7 @@ class OpenAIImageGenService(ImageGenService):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self.set_model_name(model)
|
self.set_model_name(model)
|
||||||
self._image_size = image_size
|
self._image_size = image_size
|
||||||
self._client = AsyncOpenAI(api_key=api_key)
|
self._client = AsyncOpenAI(api_key=api_key, base_url=base_url)
|
||||||
self._aiohttp_session = aiohttp_session
|
self._aiohttp_session = aiohttp_session
|
||||||
|
|
||||||
async def run_image_gen(self, prompt: str) -> AsyncGenerator[Frame, None]:
|
async def run_image_gen(self, prompt: str) -> AsyncGenerator[Frame, None]:
|
||||||
@@ -501,9 +502,11 @@ class OpenAITTSService(TTSService):
|
|||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
api_key: Optional[str] = None,
|
api_key: Optional[str] = None,
|
||||||
|
base_url: Optional[str] = None,
|
||||||
voice: str = "alloy",
|
voice: str = "alloy",
|
||||||
model: str = "gpt-4o-mini-tts",
|
model: str = "gpt-4o-mini-tts",
|
||||||
sample_rate: Optional[int] = None,
|
sample_rate: Optional[int] = None,
|
||||||
|
instructions: Optional[str] = None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
if sample_rate and sample_rate != self.OPENAI_SAMPLE_RATE:
|
if sample_rate and sample_rate != self.OPENAI_SAMPLE_RATE:
|
||||||
@@ -515,8 +518,8 @@ class OpenAITTSService(TTSService):
|
|||||||
|
|
||||||
self.set_model_name(model)
|
self.set_model_name(model)
|
||||||
self.set_voice(voice)
|
self.set_voice(voice)
|
||||||
|
self._instructions = instructions
|
||||||
self._client = AsyncOpenAI(api_key=api_key)
|
self._client = AsyncOpenAI(api_key=api_key, base_url=base_url)
|
||||||
|
|
||||||
def can_generate_metrics(self) -> bool:
|
def can_generate_metrics(self) -> bool:
|
||||||
return True
|
return True
|
||||||
@@ -538,11 +541,17 @@ class OpenAITTSService(TTSService):
|
|||||||
try:
|
try:
|
||||||
await self.start_ttfb_metrics()
|
await self.start_ttfb_metrics()
|
||||||
|
|
||||||
|
# Setup extra body parameters
|
||||||
|
extra_body = {}
|
||||||
|
if self._instructions:
|
||||||
|
extra_body["instructions"] = self._instructions
|
||||||
|
|
||||||
async with self._client.audio.speech.with_streaming_response.create(
|
async with self._client.audio.speech.with_streaming_response.create(
|
||||||
input=text or " ", # Text must contain at least one character
|
input=text or " ", # Text must contain at least one character
|
||||||
model=self.model_name,
|
model=self.model_name,
|
||||||
voice=VALID_VOICES[self._voice_id],
|
voice=VALID_VOICES[self._voice_id],
|
||||||
response_format="pcm",
|
response_format="pcm",
|
||||||
|
extra_body=extra_body,
|
||||||
) as r:
|
) as r:
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
error = await r.text()
|
error = await r.text()
|
||||||
|
|||||||
Reference in New Issue
Block a user