Skip to content

Commit 15e6f15

Browse files
[music] support new params and surfacing song id (#731)
* [music] support new params and surfacing song id * Fix param name for consistency
1 parent 9590446 commit 15e6f15

1 file changed

Lines changed: 25 additions & 16 deletions

File tree

src/elevenlabs/music_custom.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class MultipartResponse:
3030
json: typing.Dict[str, typing.Any] # Contains compositionPlan and songMetadata
3131
audio: bytes
3232
filename: str
33+
song_id: typing.Optional[str] = None
3334

3435

3536
class MusicClient(AutogeneratedMusicClient):
@@ -46,6 +47,8 @@ def compose_detailed( # type: ignore[override]
4647
composition_plan: typing.Optional[MusicPrompt] = OMIT,
4748
music_length_ms: typing.Optional[int] = OMIT,
4849
model_id: typing.Optional[typing.Literal["music_v1"]] = OMIT,
50+
force_instrumental: typing.Optional[bool] = OMIT,
51+
store_for_inpainting: typing.Optional[bool] = OMIT,
4952
with_timestamps: typing.Optional[bool] = OMIT,
5053
sign_with_c2pa: typing.Optional[bool] = OMIT,
5154
request_options: typing.Optional[RequestOptions] = None,
@@ -55,23 +58,25 @@ def compose_detailed( # type: ignore[override]
5558
Compose a song from a prompt or a composition plan with detailed response parsing.
5659
This method calls the original compose_detailed and then parses the stream response.
5760
58-
Returns a MultipartResponse containing parsed JSON metadata, audio bytes, and filename.
61+
Returns a MultipartResponse containing parsed JSON metadata, audio bytes, filename,
62+
and song_id (if store_for_inpainting was True).
5963
"""
60-
# Call the parent method to get the stream
61-
stream = super().compose_detailed(
64+
# Use the raw client directly to access response headers (for song_id)
65+
with self._raw_client.compose_detailed(
6266
output_format=output_format,
6367
prompt=prompt,
6468
composition_plan=composition_plan,
6569
music_length_ms=music_length_ms,
6670
model_id=model_id,
71+
force_instrumental=force_instrumental,
72+
store_for_inpainting=store_for_inpainting,
6773
with_timestamps=with_timestamps,
6874
sign_with_c_2_pa=sign_with_c2pa,
6975
request_options=request_options,
70-
**kwargs,
71-
)
72-
73-
# Parse the stream using the parsing method
74-
return self._parse_multipart(stream)
76+
) as r:
77+
result = self._parse_multipart(r.data)
78+
result.song_id = r.headers.get("song-id")
79+
return result
7580

7681
def _parse_multipart(self, stream: typing.Iterator[bytes]) -> MultipartResponse:
7782
"""
@@ -178,6 +183,8 @@ async def compose_detailed( # type: ignore[override]
178183
composition_plan: typing.Optional[MusicPrompt] = OMIT,
179184
music_length_ms: typing.Optional[int] = OMIT,
180185
model_id: typing.Optional[typing.Literal["music_v1"]] = OMIT,
186+
force_instrumental: typing.Optional[bool] = OMIT,
187+
store_for_inpainting: typing.Optional[bool] = OMIT,
181188
with_timestamps: typing.Optional[bool] = OMIT,
182189
sign_with_c2pa: typing.Optional[bool] = OMIT,
183190
request_options: typing.Optional[RequestOptions] = None,
@@ -187,23 +194,25 @@ async def compose_detailed( # type: ignore[override]
187194
Compose a song from a prompt or a composition plan with detailed response parsing.
188195
This method calls the original compose_detailed and then parses the stream response.
189196
190-
Returns a MultipartResponse containing parsed JSON metadata, audio bytes, and filename.
197+
Returns a MultipartResponse containing parsed JSON metadata, audio bytes, filename,
198+
and song_id (if store_for_inpainting was True).
191199
"""
192-
# Call the parent method to get the stream
193-
stream = super().compose_detailed(
200+
# Use the raw client directly to access response headers (for song_id)
201+
async with self._raw_client.compose_detailed(
194202
output_format=output_format,
195203
prompt=prompt,
196204
composition_plan=composition_plan,
197205
music_length_ms=music_length_ms,
198206
model_id=model_id,
207+
force_instrumental=force_instrumental,
208+
store_for_inpainting=store_for_inpainting,
199209
with_timestamps=with_timestamps,
200210
sign_with_c_2_pa=sign_with_c2pa,
201211
request_options=request_options,
202-
**kwargs,
203-
)
204-
205-
# Parse the stream using the parsing method
206-
return await self._parse_multipart_async(stream)
212+
) as r:
213+
result = await self._parse_multipart_async(r.data)
214+
result.song_id = r.headers.get("song-id")
215+
return result
207216

208217
async def _parse_multipart_async(self, stream: typing.AsyncIterator[bytes]) -> MultipartResponse:
209218
"""

0 commit comments

Comments
 (0)