Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/elevenlabs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
BatchCallRecipientStatus,
BatchCallResponse,
BatchCallStatus,
BodyComposeMusicWithADetailedResponseV1MusicDetailedPost,
BodyGenerateARandomVoiceV1VoiceGenerationGenerateVoicePostAge,
BodyGenerateARandomVoiceV1VoiceGenerationGenerateVoicePostGender,
BreakdownTypes,
Expand Down Expand Up @@ -769,7 +768,11 @@
from .dubbing import DubbingListRequestDubbingStatus, DubbingListRequestFilterByCreator
from .environment import ElevenLabsEnvironment
from .history import HistoryListRequestSource
from .music import MusicComposeRequestOutputFormat, MusicStreamRequestOutputFormat
from .music import (
MusicComposeDetailedRequestOutputFormat,
MusicComposeRequestOutputFormat,
MusicStreamRequestOutputFormat,
)
from .play import play, save, stream
from .pronunciation_dictionaries import (
BodyAddAPronunciationDictionaryV1PronunciationDictionariesAddFromRulesPostRulesItem,
Expand Down Expand Up @@ -886,7 +889,6 @@
"BodyAddAPronunciationDictionaryV1PronunciationDictionariesAddFromRulesPostRulesItem_Alias",
"BodyAddAPronunciationDictionaryV1PronunciationDictionariesAddFromRulesPostRulesItem_Phoneme",
"BodyAddAPronunciationDictionaryV1PronunciationDictionariesAddFromRulesPostWorkspaceAccess",
"BodyComposeMusicWithADetailedResponseV1MusicDetailedPost",
"BodyCreatePodcastV1StudioPodcastsPostDurationScale",
"BodyCreatePodcastV1StudioPodcastsPostMode",
"BodyCreatePodcastV1StudioPodcastsPostMode_Bulletin",
Expand Down Expand Up @@ -1270,6 +1272,7 @@
"ModerationStatusResponseModelSafetyStatus",
"ModerationStatusResponseModelWarningStatus",
"MultichannelSpeechToTextResponseModel",
"MusicComposeDetailedRequestOutputFormat",
"MusicComposeRequestOutputFormat",
"MusicPrompt",
"MusicStreamRequestOutputFormat",
Expand Down
3 changes: 3 additions & 0 deletions src/elevenlabs/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .environment import ElevenLabsEnvironment
from .realtime_tts import RealtimeTextToSpeechClient
from .webhooks_custom import WebhooksClient, AsyncWebhooksClient
from .music_custom import MusicClient, AsyncMusicClient


# this is used as the default value for optional parameters
Expand Down Expand Up @@ -59,6 +60,7 @@ def __init__(
)
self.text_to_speech = RealtimeTextToSpeechClient(client_wrapper=self._client_wrapper)
self.webhooks = WebhooksClient(client_wrapper=self._client_wrapper)
self.music = MusicClient(client_wrapper=self._client_wrapper)


class AsyncElevenLabs(AsyncBaseElevenLabs):
Expand Down Expand Up @@ -102,3 +104,4 @@ def __init__(
httpx_client=httpx_client
)
self.webhooks = AsyncWebhooksClient(client_wrapper=self._client_wrapper)
self.music = AsyncMusicClient(client_wrapper=self._client_wrapper)
4 changes: 2 additions & 2 deletions src/elevenlabs/core/client_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def __init__(self, *, api_key: typing.Optional[str] = None, base_url: str, timeo

def get_headers(self) -> typing.Dict[str, str]:
headers: typing.Dict[str, str] = {
"User-Agent": "elevenlabs/v2.10.0",
"User-Agent": "elevenlabs/v2.11.0",
"X-Fern-Language": "Python",
"X-Fern-SDK-Name": "elevenlabs",
"X-Fern-SDK-Version": "v2.10.0",
"X-Fern-SDK-Version": "v2.11.0",
}
if self._api_key is not None:
headers["xi-api-key"] = self._api_key
Expand Down
13 changes: 11 additions & 2 deletions src/elevenlabs/music/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@

# isort: skip_file

from .types import MusicComposeRequestOutputFormat, MusicStreamRequestOutputFormat
from .types import (
MusicComposeDetailedRequestOutputFormat,
MusicComposeRequestOutputFormat,
MusicStreamRequestOutputFormat,
)
from . import composition_plan

__all__ = ["MusicComposeRequestOutputFormat", "MusicStreamRequestOutputFormat", "composition_plan"]
__all__ = [
"MusicComposeDetailedRequestOutputFormat",
"MusicComposeRequestOutputFormat",
"MusicStreamRequestOutputFormat",
"composition_plan",
]
108 changes: 108 additions & 0 deletions src/elevenlabs/music/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ..types.music_prompt import MusicPrompt
from .composition_plan.client import AsyncCompositionPlanClient, CompositionPlanClient
from .raw_client import AsyncRawMusicClient, RawMusicClient
from .types.music_compose_detailed_request_output_format import MusicComposeDetailedRequestOutputFormat
from .types.music_compose_request_output_format import MusicComposeRequestOutputFormat
from .types.music_stream_request_output_format import MusicStreamRequestOutputFormat

Expand Down Expand Up @@ -83,6 +84,59 @@ def compose(
) as r:
yield from r.data

def compose_detailed(
self,
*,
output_format: typing.Optional[MusicComposeDetailedRequestOutputFormat] = None,
prompt: typing.Optional[str] = OMIT,
music_prompt: typing.Optional[MusicPrompt] = OMIT,
composition_plan: typing.Optional[MusicPrompt] = OMIT,
music_length_ms: typing.Optional[int] = OMIT,
model_id: typing.Optional[typing.Literal["music_v1"]] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> typing.Iterator[bytes]:
"""
Compose a song from a prompt or a composition plan.

Parameters
----------
output_format : typing.Optional[MusicComposeDetailedRequestOutputFormat]
Output format of the generated audio. Formatted as codec_sample_rate_bitrate. So an mp3 with 22.05kHz sample rate at 32kbs is represented as mp3_22050_32. MP3 with 192kbps bitrate requires you to be subscribed to Creator tier or above. PCM with 44.1kHz sample rate requires you to be subscribed to Pro tier or above. Note that the μ-law format (sometimes written mu-law, often approximated as u-law) is commonly used for Twilio audio inputs.

prompt : typing.Optional[str]
A simple text prompt to generate a song from. Cannot be used in conjunction with `composition_plan`.

music_prompt : typing.Optional[MusicPrompt]
A music prompt. Deprecated. Use `composition_plan` instead.

composition_plan : typing.Optional[MusicPrompt]
A detailed composition plan to guide music generation. Cannot be used in conjunction with `prompt`.

music_length_ms : typing.Optional[int]
The length of the song to generate in milliseconds. Used only in conjunction with `prompt`. Must be between 10000ms and 300000ms. Optional - if not provided, the model will choose a length based on the prompt.

model_id : typing.Optional[typing.Literal["music_v1"]]
The model to use for the generation.

request_options : typing.Optional[RequestOptions]
Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response.

Returns
-------
typing.Iterator[bytes]
Successful Response
"""
with self._raw_client.compose_detailed(
output_format=output_format,
prompt=prompt,
music_prompt=music_prompt,
composition_plan=composition_plan,
music_length_ms=music_length_ms,
model_id=model_id,
request_options=request_options,
) as r:
yield from r.data

def stream(
self,
*,
Expand Down Expand Up @@ -207,6 +261,60 @@ async def compose(
async for _chunk in r.data:
yield _chunk

async def compose_detailed(
self,
*,
output_format: typing.Optional[MusicComposeDetailedRequestOutputFormat] = None,
prompt: typing.Optional[str] = OMIT,
music_prompt: typing.Optional[MusicPrompt] = OMIT,
composition_plan: typing.Optional[MusicPrompt] = OMIT,
music_length_ms: typing.Optional[int] = OMIT,
model_id: typing.Optional[typing.Literal["music_v1"]] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> typing.AsyncIterator[bytes]:
"""
Compose a song from a prompt or a composition plan.

Parameters
----------
output_format : typing.Optional[MusicComposeDetailedRequestOutputFormat]
Output format of the generated audio. Formatted as codec_sample_rate_bitrate. So an mp3 with 22.05kHz sample rate at 32kbs is represented as mp3_22050_32. MP3 with 192kbps bitrate requires you to be subscribed to Creator tier or above. PCM with 44.1kHz sample rate requires you to be subscribed to Pro tier or above. Note that the μ-law format (sometimes written mu-law, often approximated as u-law) is commonly used for Twilio audio inputs.

prompt : typing.Optional[str]
A simple text prompt to generate a song from. Cannot be used in conjunction with `composition_plan`.

music_prompt : typing.Optional[MusicPrompt]
A music prompt. Deprecated. Use `composition_plan` instead.

composition_plan : typing.Optional[MusicPrompt]
A detailed composition plan to guide music generation. Cannot be used in conjunction with `prompt`.

music_length_ms : typing.Optional[int]
The length of the song to generate in milliseconds. Used only in conjunction with `prompt`. Must be between 10000ms and 300000ms. Optional - if not provided, the model will choose a length based on the prompt.

model_id : typing.Optional[typing.Literal["music_v1"]]
The model to use for the generation.

request_options : typing.Optional[RequestOptions]
Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response.

Returns
-------
typing.AsyncIterator[bytes]
Successful Response
"""
async with self._raw_client.compose_detailed(
output_format=output_format,
prompt=prompt,
music_prompt=music_prompt,
composition_plan=composition_plan,
music_length_ms=music_length_ms,
model_id=model_id,
request_options=request_options,
) as r:
async for _chunk in r.data:
yield _chunk

async def stream(
self,
*,
Expand Down
Loading