Skip to content

Commit 7af17bc

Browse files
authored
(fix): websocket api respects output format (elevenlabs#321)
1 parent 2388145 commit 7af17bc

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "elevenlabs"
3-
version = "v1.4.1"
3+
version = "v1.5.0"
44
description = ""
55
readme = "README.md"
66
authors = []

src/elevenlabs/client.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
PronunciationDictionaryVersionLocator, Model
1515
from .environment import ElevenLabsEnvironment
1616
from .realtime_tts import RealtimeTextToSpeechClient
17+
from .types import OutputFormat
1718

1819

1920
DEFAULT_VOICE = Voice(
@@ -124,7 +125,7 @@ def generate(
124125
model: Union[ModelId, Model] = "eleven_monolingual_v1",
125126
optimize_streaming_latency: typing.Optional[int] = 0,
126127
stream: bool = False,
127-
output_format: Optional[str] = "mp3_44100_128",
128+
output_format: Optional[OutputFormat] = "mp3_44100_128",
128129
pronunciation_dictionary_locators: typing.Optional[
129130
typing.Sequence[PronunciationDictionaryVersionLocator]
130131
] = OMIT,
@@ -152,7 +153,7 @@ def generate(
152153
153154
Defaults to False.
154155
155-
- output_format: typing.Optional[str]. Output format of the generated audio. Must be one of:
156+
- output_format: typing.Optional[OutputFormat]. Output format of the generated audio. Must be one of:
156157
mp3_22050_32 - output format, mp3 with 22.05kHz sample rate at 32kbps.
157158
mp3_44100_32 - output format, mp3 with 44.1kHz sample rate at 32kbps.
158159
mp3_44100_64 - output format, mp3 with 44.1kHz sample rate at 64kbps.
@@ -303,7 +304,7 @@ async def generate(
303304
model: Union[ModelId, Model] = "eleven_monolingual_v1",
304305
optimize_streaming_latency: typing.Optional[int] = 0,
305306
stream: bool = False,
306-
output_format: Optional[str] = "mp3_44100_128",
307+
output_format: Optional[OutputFormat] = "mp3_44100_128",
307308
pronunciation_dictionary_locators: typing.Optional[
308309
typing.Sequence[PronunciationDictionaryVersionLocator]
309310
] = OMIT,
@@ -338,7 +339,7 @@ async def generate(
338339
339340
Defaults to False.
340341
341-
- output_format: typing.Optional[str]. Output format of the generated audio. Must be one of:
342+
- output_format: typing.Optional[OutputFormat]. Output format of the generated audio. Must be one of:
342343
mp3_22050_32 - output format, mp3 with 22.05kHz sample rate at 32kbps.
343344
mp3_44100_32 - output format, mp3 with 44.1kHz sample rate at 32kbps.
344345
mp3_44100_64 - output format, mp3 with 44.1kHz sample rate at 64kbps.

src/elevenlabs/realtime_tts.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from .core.request_options import RequestOptions
1515
from .types.voice_settings import VoiceSettings
1616
from .text_to_speech.client import TextToSpeechClient
17+
from .types import OutputFormat
1718

1819
# this is used as the default value for optional parameters
1920
OMIT = typing.cast(typing.Any, ...)
@@ -45,6 +46,7 @@ def convert_realtime(
4546
*,
4647
text: typing.Iterator[str],
4748
model_id: typing.Optional[str] = OMIT,
49+
output_format: typing.Optional[OutputFormat] = "mp3_44100_128",
4850
voice_settings: typing.Optional[VoiceSettings] = OMIT,
4951
request_options: typing.Optional[RequestOptions] = None,
5052
) -> typing.Iterator[bytes]:
@@ -86,7 +88,8 @@ def get_text() -> typing.Iterator[str]:
8688
"""
8789
with connect(
8890
urllib.parse.urljoin(
89-
"wss://api.elevenlabs.io/", f"v1/text-to-speech/{jsonable_encoder(voice_id)}/stream-input?model_id={model_id}"
91+
"wss://api.elevenlabs.io/",
92+
f"v1/text-to-speech/{jsonable_encoder(voice_id)}/stream-input?model_id={model_id}&output_format={output_format}"
9093
),
9194
additional_headers=jsonable_encoder(
9295
remove_none_from_dict(

0 commit comments

Comments
 (0)