@elevenlabs/elevenlabs-js 2.20.0 → 2.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Client.js CHANGED
@@ -77,8 +77,8 @@ class ElevenLabsClient {
77
77
  "xi-api-key": _options === null || _options === void 0 ? void 0 : _options.apiKey,
78
78
  "X-Fern-Language": "JavaScript",
79
79
  "X-Fern-SDK-Name": "@elevenlabs/elevenlabs-js",
80
- "X-Fern-SDK-Version": "v2.20.0",
81
- "User-Agent": "@elevenlabs/elevenlabs-js/v2.20.0",
80
+ "X-Fern-SDK-Version": "v2.20.1",
81
+ "User-Agent": "@elevenlabs/elevenlabs-js/v2.20.1",
82
82
  "X-Fern-Runtime": core.RUNTIME.type,
83
83
  "X-Fern-Runtime-Version": core.RUNTIME.version,
84
84
  }, _options === null || _options === void 0 ? void 0 : _options.headers) });
package/dist/Client.js CHANGED
@@ -77,8 +77,8 @@ class ElevenLabsClient {
77
77
  "xi-api-key": _options === null || _options === void 0 ? void 0 : _options.apiKey,
78
78
  "X-Fern-Language": "JavaScript",
79
79
  "X-Fern-SDK-Name": "@elevenlabs/elevenlabs-js",
80
- "X-Fern-SDK-Version": "v2.20.0",
81
- "User-Agent": "@elevenlabs/elevenlabs-js/v2.20.0",
80
+ "X-Fern-SDK-Version": "v2.20.1",
81
+ "User-Agent": "@elevenlabs/elevenlabs-js/v2.20.1",
82
82
  "X-Fern-Runtime": core.RUNTIME.type,
83
83
  "X-Fern-Runtime-Version": core.RUNTIME.version,
84
84
  }, _options === null || _options === void 0 ? void 0 : _options.headers) });
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "v2.20.0";
1
+ export declare const SDK_VERSION = "v2.20.1";
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = "v2.20.0";
4
+ exports.SDK_VERSION = "v2.20.1";
@@ -57,7 +57,7 @@ class ElevenLabsClient extends Client_1.ElevenLabsClient {
57
57
  }
58
58
  return this._customWebhooks;
59
59
  }
60
- // @ts-expect-error - Intentionally overriding parent getter with custom Music wrapper
60
+ // @ts-expect-error - Intentionally overriding with wrapper Music that has enhanced composeDetailed
61
61
  get music() {
62
62
  if (!this._customMusic) {
63
63
  this._customMusic = new music_1.Music(this._options);
@@ -1,6 +1,7 @@
1
1
  import { Music as GeneratedMusic } from "../api/resources/music/client/Client";
2
2
  import type * as ElevenLabs from "../api";
3
3
  import type { CompositionPlan } from "../api/resources/music/resources/compositionPlan/client/Client";
4
+ import * as core from "../core";
4
5
  export declare namespace Music {
5
6
  interface Options extends GeneratedMusic.Options {
6
7
  }
@@ -22,14 +23,84 @@ export interface MultipartResponse {
22
23
  audio: Buffer;
23
24
  filename: string;
24
25
  }
25
- export declare class Music extends GeneratedMusic {
26
+ export declare class Music {
27
+ private _client;
26
28
  constructor(options?: Music.Options);
29
+ /**
30
+ * Get the composition plan client
31
+ */
32
+ get compositionPlan(): CompositionPlan;
33
+ /**
34
+ * Compose a song from a prompt or a composition plan.
35
+ * @throws {@link ElevenLabs.UnprocessableEntityError}
36
+ */
37
+ compose(request?: ElevenLabs.BodyComposeMusicV1MusicPost, requestOptions?: Music.RequestOptions): core.HttpResponsePromise<ReadableStream<Uint8Array>>;
27
38
  /**
28
39
  * Compose a song from a prompt or a composition plan with detailed response parsing.
29
- * This method calls the original composeDetailed and then parses the stream response.
40
+ *
41
+ * Unlike the standard `compose()` method which returns a raw audio stream, this method
42
+ * automatically parses the multipart response to extract both the audio file and rich
43
+ * metadata about the generated composition.
44
+ *
45
+ * @param request - The music composition request containing either:
46
+ * - `prompt`: A text description of the desired music (e.g., "upbeat electronic dance music")
47
+ * - `compositionPlan`: A detailed composition plan object created via `compositionPlan.create()`
48
+ * - `musicLengthMs`: Optional duration in milliseconds (10000-300000ms)
49
+ *
50
+ * @param requestOptions - Optional request configuration (e.g., timeout, signal, headers)
51
+ *
52
+ * @returns A promise that resolves to a `MultipartResponse` containing:
53
+ * - `json.compositionPlan`: The detailed composition plan structure including sections,
54
+ * styles, and lyrics
55
+ * - `json.songMetadata`: Metadata about the generated song (title, description, genres,
56
+ * languages, explicit content flag)
57
+ * - `audio`: Buffer containing the complete audio file (MP3 format)
58
+ * - `filename`: Suggested filename for the audio file
59
+ *
60
+ * @throws {@link ElevenLabs.UnprocessableEntityError} If the request parameters are invalid
61
+ * or the music generation fails
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const client = new ElevenLabs({ apiKey: "your-api-key" });
66
+ *
67
+ * // Generate music from a text prompt
68
+ * const response = await client.music.composeDetailed({
69
+ * prompt: "Epic orchestral music with dramatic strings and powerful brass",
70
+ * musicLengthMs: 60000 // 60 seconds
71
+ * });
72
+ *
73
+ * console.log("Title:", response.json.songMetadata.title);
74
+ * console.log("Genres:", response.json.songMetadata.genres);
75
+ *
76
+ * // Save the audio to a file
77
+ * fs.writeFileSync(response.filename, response.audio);
78
+ * ```
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * // Generate music from a composition plan
83
+ * const plan = await client.music.compositionPlan.create({
84
+ * prompt: "A progressive rock song about space exploration"
85
+ * });
86
+ *
87
+ * const response = await client.music.composeDetailed({
88
+ * compositionPlan: plan.compositionPlan
89
+ * });
90
+ *
91
+ * // Access detailed section information
92
+ * for (const section of response.json.compositionPlan.sections) {
93
+ * console.log(`${section.sectionName}: ${section.durationMs}ms`);
94
+ * }
95
+ * ```
96
+ */
97
+ composeDetailed(request?: ElevenLabs.BodyComposeMusicWithADetailedResponseV1MusicDetailedPost, requestOptions?: Music.RequestOptions): core.HttpResponsePromise<MultipartResponse>;
98
+ private _composeDetailed;
99
+ /**
100
+ * Stream a composed song from a prompt or a composition plan.
30
101
  * @throws {@link ElevenLabs.UnprocessableEntityError}
31
102
  */
32
- composeDetailed(request?: ElevenLabs.BodyComposeMusicWithADetailedResponseV1MusicDetailedPost, requestOptions?: Music.RequestOptions): Promise<MultipartResponse>;
103
+ stream(request?: ElevenLabs.BodyStreamComposedMusicV1MusicStreamPost, requestOptions?: Music.RequestOptions): core.HttpResponsePromise<ReadableStream<Uint8Array>>;
33
104
  /**
34
105
  * Reads a ReadableStream containing multipart data and parses it into JSON and audio parts
35
106
  * @param stream - ReadableStream from ElevenLabs music API response
@@ -1,4 +1,37 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -11,28 +44,108 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
44
  Object.defineProperty(exports, "__esModule", { value: true });
12
45
  exports.Music = void 0;
13
46
  const Client_1 = require("../api/resources/music/client/Client");
14
- class Music extends Client_1.Music {
47
+ const core = __importStar(require("../core"));
48
+ class Music {
15
49
  constructor(options = {}) {
16
- super(options);
50
+ this._client = new Client_1.Music(options);
17
51
  }
18
52
  /**
19
- * Compose a song from a prompt or a composition plan with detailed response parsing.
20
- * This method calls the original composeDetailed and then parses the stream response.
53
+ * Get the composition plan client
54
+ */
55
+ get compositionPlan() {
56
+ return this._client.compositionPlan;
57
+ }
58
+ /**
59
+ * Compose a song from a prompt or a composition plan.
21
60
  * @throws {@link ElevenLabs.UnprocessableEntityError}
22
61
  */
23
- // @ts-expect-error - Intentionally overriding parent method with different return type
24
- composeDetailed() {
25
- const _super = Object.create(null, {
26
- composeDetailed: { get: () => super.composeDetailed }
27
- });
62
+ compose(request = {}, requestOptions) {
63
+ return this._client.compose(request, requestOptions);
64
+ }
65
+ /**
66
+ * Compose a song from a prompt or a composition plan with detailed response parsing.
67
+ *
68
+ * Unlike the standard `compose()` method which returns a raw audio stream, this method
69
+ * automatically parses the multipart response to extract both the audio file and rich
70
+ * metadata about the generated composition.
71
+ *
72
+ * @param request - The music composition request containing either:
73
+ * - `prompt`: A text description of the desired music (e.g., "upbeat electronic dance music")
74
+ * - `compositionPlan`: A detailed composition plan object created via `compositionPlan.create()`
75
+ * - `musicLengthMs`: Optional duration in milliseconds (10000-300000ms)
76
+ *
77
+ * @param requestOptions - Optional request configuration (e.g., timeout, signal, headers)
78
+ *
79
+ * @returns A promise that resolves to a `MultipartResponse` containing:
80
+ * - `json.compositionPlan`: The detailed composition plan structure including sections,
81
+ * styles, and lyrics
82
+ * - `json.songMetadata`: Metadata about the generated song (title, description, genres,
83
+ * languages, explicit content flag)
84
+ * - `audio`: Buffer containing the complete audio file (MP3 format)
85
+ * - `filename`: Suggested filename for the audio file
86
+ *
87
+ * @throws {@link ElevenLabs.UnprocessableEntityError} If the request parameters are invalid
88
+ * or the music generation fails
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * const client = new ElevenLabs({ apiKey: "your-api-key" });
93
+ *
94
+ * // Generate music from a text prompt
95
+ * const response = await client.music.composeDetailed({
96
+ * prompt: "Epic orchestral music with dramatic strings and powerful brass",
97
+ * musicLengthMs: 60000 // 60 seconds
98
+ * });
99
+ *
100
+ * console.log("Title:", response.json.songMetadata.title);
101
+ * console.log("Genres:", response.json.songMetadata.genres);
102
+ *
103
+ * // Save the audio to a file
104
+ * fs.writeFileSync(response.filename, response.audio);
105
+ * ```
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * // Generate music from a composition plan
110
+ * const plan = await client.music.compositionPlan.create({
111
+ * prompt: "A progressive rock song about space exploration"
112
+ * });
113
+ *
114
+ * const response = await client.music.composeDetailed({
115
+ * compositionPlan: plan.compositionPlan
116
+ * });
117
+ *
118
+ * // Access detailed section information
119
+ * for (const section of response.json.compositionPlan.sections) {
120
+ * console.log(`${section.sectionName}: ${section.durationMs}ms`);
121
+ * }
122
+ * ```
123
+ */
124
+ composeDetailed(request = {}, requestOptions) {
125
+ return core.HttpResponsePromise.fromPromise(this._composeDetailed(request, requestOptions));
126
+ }
127
+ _composeDetailed() {
28
128
  return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
29
- // Call the parent method to get the stream
30
- const response = yield _super.composeDetailed.call(this, request, requestOptions);
31
- // Parse the stream using your existing parsing method
32
- const parsedResponse = yield this.parseMultipart(response);
33
- return parsedResponse;
129
+ // Call the base client method to get the stream with raw response
130
+ try {
131
+ const { data: stream, rawResponse } = yield this._client.composeDetailed(request, requestOptions).withRawResponse();
132
+ // Parse the stream using the existing parsing method
133
+ const parsedResponse = yield this.parseMultipart(stream);
134
+ return { data: parsedResponse, rawResponse };
135
+ }
136
+ catch (error) {
137
+ const message = error instanceof Error ? error.message : String(error);
138
+ throw new Error(`Failed to parse detailed composition response: ${message}`);
139
+ }
34
140
  });
35
141
  }
142
+ /**
143
+ * Stream a composed song from a prompt or a composition plan.
144
+ * @throws {@link ElevenLabs.UnprocessableEntityError}
145
+ */
146
+ stream(request = {}, requestOptions) {
147
+ return this._client.stream(request, requestOptions);
148
+ }
36
149
  /**
37
150
  * Reads a ReadableStream containing multipart data and parses it into JSON and audio parts
38
151
  * @param stream - ReadableStream from ElevenLabs music API response
@@ -98,7 +98,6 @@ class RealtimeConnection {
98
98
  break;
99
99
  case "final_transcript_with_timestamps":
100
100
  this.eventEmitter.emit(RealtimeEvents.FINAL_TRANSCRIPT_WITH_TIMESTAMPS, data);
101
- this.close();
102
101
  break;
103
102
  }
104
103
  });
@@ -44,6 +44,11 @@ interface BaseOptions {
44
44
  * Must be a valid model ID.
45
45
  */
46
46
  modelId: string;
47
+ /**
48
+ * An ISO-639-1 or ISO-639-3 language_code corresponding to the language of the audio file.
49
+ * Can sometimes improve transcription performance if known beforehand.
50
+ */
51
+ languageCode?: string;
47
52
  }
48
53
  export interface AudioOptions extends BaseOptions {
49
54
  audioFormat: AudioFormat;
@@ -133,6 +133,9 @@ class ScribeRealtime {
133
133
  }
134
134
  params.append("min_silence_duration_ms", options.minSilenceDurationMs.toString());
135
135
  }
136
+ if (options.languageCode !== undefined) {
137
+ params.append("language_code", options.languageCode);
138
+ }
136
139
  const queryString = params.toString();
137
140
  return queryString ? `${baseUri}?${queryString}` : baseUri;
138
141
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elevenlabs/elevenlabs-js",
3
- "version": "v2.20.0",
3
+ "version": "v2.20.1",
4
4
  "private": false,
5
5
  "repository": "github:elevenlabs/elevenlabs-js",
6
6
  "license": "MIT",
@@ -15,24 +15,25 @@
15
15
  "test:wire": "jest --selectProjects wire"
16
16
  },
17
17
  "dependencies": {
18
+ "command-exists": "^1.2.9",
18
19
  "node-fetch": "^2.7.0",
19
- "command-exists": "^1.2.9"
20
+ "ws": "^8.18.3"
20
21
  },
21
22
  "devDependencies": {
22
- "@types/node-fetch": "^2.6.12",
23
- "webpack": "^5.97.1",
24
- "ts-loader": "^9.5.1",
25
- "jest": "^29.7.0",
26
23
  "@jest/globals": "^29.7.0",
24
+ "@types/command-exists": "^1.2.3",
27
25
  "@types/jest": "^29.5.5",
28
- "ts-jest": "^29.1.1",
26
+ "@types/node": "^18.19.70",
27
+ "@types/node-fetch": "^2.6.12",
28
+ "@types/ws": "^8.18.1",
29
+ "jest": "^29.7.0",
29
30
  "jest-environment-jsdom": "^29.7.0",
30
31
  "msw": "2.11.2",
31
- "@types/node": "^18.19.70",
32
32
  "prettier": "^3.4.2",
33
+ "ts-jest": "^29.1.1",
34
+ "ts-loader": "^9.5.1",
33
35
  "typescript": "~5.7.2",
34
- "@types/command-exists": "^1.2.3",
35
- "@types/ws": "^8.18.1"
36
+ "webpack": "^5.97.1"
36
37
  },
37
38
  "browser": {
38
39
  "fs": false,
package/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "v2.20.0";
1
+ export declare const SDK_VERSION = "v2.20.1";
package/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = "v2.20.0";
4
+ exports.SDK_VERSION = "v2.20.1";
@@ -57,7 +57,7 @@ class ElevenLabsClient extends Client_1.ElevenLabsClient {
57
57
  }
58
58
  return this._customWebhooks;
59
59
  }
60
- // @ts-expect-error - Intentionally overriding parent getter with custom Music wrapper
60
+ // @ts-expect-error - Intentionally overriding with wrapper Music that has enhanced composeDetailed
61
61
  get music() {
62
62
  if (!this._customMusic) {
63
63
  this._customMusic = new music_1.Music(this._options);
@@ -1,6 +1,7 @@
1
1
  import { Music as GeneratedMusic } from "../api/resources/music/client/Client";
2
2
  import type * as ElevenLabs from "../api";
3
3
  import type { CompositionPlan } from "../api/resources/music/resources/compositionPlan/client/Client";
4
+ import * as core from "../core";
4
5
  export declare namespace Music {
5
6
  interface Options extends GeneratedMusic.Options {
6
7
  }
@@ -22,14 +23,84 @@ export interface MultipartResponse {
22
23
  audio: Buffer;
23
24
  filename: string;
24
25
  }
25
- export declare class Music extends GeneratedMusic {
26
+ export declare class Music {
27
+ private _client;
26
28
  constructor(options?: Music.Options);
29
+ /**
30
+ * Get the composition plan client
31
+ */
32
+ get compositionPlan(): CompositionPlan;
33
+ /**
34
+ * Compose a song from a prompt or a composition plan.
35
+ * @throws {@link ElevenLabs.UnprocessableEntityError}
36
+ */
37
+ compose(request?: ElevenLabs.BodyComposeMusicV1MusicPost, requestOptions?: Music.RequestOptions): core.HttpResponsePromise<ReadableStream<Uint8Array>>;
27
38
  /**
28
39
  * Compose a song from a prompt or a composition plan with detailed response parsing.
29
- * This method calls the original composeDetailed and then parses the stream response.
40
+ *
41
+ * Unlike the standard `compose()` method which returns a raw audio stream, this method
42
+ * automatically parses the multipart response to extract both the audio file and rich
43
+ * metadata about the generated composition.
44
+ *
45
+ * @param request - The music composition request containing either:
46
+ * - `prompt`: A text description of the desired music (e.g., "upbeat electronic dance music")
47
+ * - `compositionPlan`: A detailed composition plan object created via `compositionPlan.create()`
48
+ * - `musicLengthMs`: Optional duration in milliseconds (10000-300000ms)
49
+ *
50
+ * @param requestOptions - Optional request configuration (e.g., timeout, signal, headers)
51
+ *
52
+ * @returns A promise that resolves to a `MultipartResponse` containing:
53
+ * - `json.compositionPlan`: The detailed composition plan structure including sections,
54
+ * styles, and lyrics
55
+ * - `json.songMetadata`: Metadata about the generated song (title, description, genres,
56
+ * languages, explicit content flag)
57
+ * - `audio`: Buffer containing the complete audio file (MP3 format)
58
+ * - `filename`: Suggested filename for the audio file
59
+ *
60
+ * @throws {@link ElevenLabs.UnprocessableEntityError} If the request parameters are invalid
61
+ * or the music generation fails
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const client = new ElevenLabs({ apiKey: "your-api-key" });
66
+ *
67
+ * // Generate music from a text prompt
68
+ * const response = await client.music.composeDetailed({
69
+ * prompt: "Epic orchestral music with dramatic strings and powerful brass",
70
+ * musicLengthMs: 60000 // 60 seconds
71
+ * });
72
+ *
73
+ * console.log("Title:", response.json.songMetadata.title);
74
+ * console.log("Genres:", response.json.songMetadata.genres);
75
+ *
76
+ * // Save the audio to a file
77
+ * fs.writeFileSync(response.filename, response.audio);
78
+ * ```
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * // Generate music from a composition plan
83
+ * const plan = await client.music.compositionPlan.create({
84
+ * prompt: "A progressive rock song about space exploration"
85
+ * });
86
+ *
87
+ * const response = await client.music.composeDetailed({
88
+ * compositionPlan: plan.compositionPlan
89
+ * });
90
+ *
91
+ * // Access detailed section information
92
+ * for (const section of response.json.compositionPlan.sections) {
93
+ * console.log(`${section.sectionName}: ${section.durationMs}ms`);
94
+ * }
95
+ * ```
96
+ */
97
+ composeDetailed(request?: ElevenLabs.BodyComposeMusicWithADetailedResponseV1MusicDetailedPost, requestOptions?: Music.RequestOptions): core.HttpResponsePromise<MultipartResponse>;
98
+ private _composeDetailed;
99
+ /**
100
+ * Stream a composed song from a prompt or a composition plan.
30
101
  * @throws {@link ElevenLabs.UnprocessableEntityError}
31
102
  */
32
- composeDetailed(request?: ElevenLabs.BodyComposeMusicWithADetailedResponseV1MusicDetailedPost, requestOptions?: Music.RequestOptions): Promise<MultipartResponse>;
103
+ stream(request?: ElevenLabs.BodyStreamComposedMusicV1MusicStreamPost, requestOptions?: Music.RequestOptions): core.HttpResponsePromise<ReadableStream<Uint8Array>>;
33
104
  /**
34
105
  * Reads a ReadableStream containing multipart data and parses it into JSON and audio parts
35
106
  * @param stream - ReadableStream from ElevenLabs music API response
package/wrapper/music.js CHANGED
@@ -1,4 +1,37 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -11,28 +44,108 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
44
  Object.defineProperty(exports, "__esModule", { value: true });
12
45
  exports.Music = void 0;
13
46
  const Client_1 = require("../api/resources/music/client/Client");
14
- class Music extends Client_1.Music {
47
+ const core = __importStar(require("../core"));
48
+ class Music {
15
49
  constructor(options = {}) {
16
- super(options);
50
+ this._client = new Client_1.Music(options);
17
51
  }
18
52
  /**
19
- * Compose a song from a prompt or a composition plan with detailed response parsing.
20
- * This method calls the original composeDetailed and then parses the stream response.
53
+ * Get the composition plan client
54
+ */
55
+ get compositionPlan() {
56
+ return this._client.compositionPlan;
57
+ }
58
+ /**
59
+ * Compose a song from a prompt or a composition plan.
21
60
  * @throws {@link ElevenLabs.UnprocessableEntityError}
22
61
  */
23
- // @ts-expect-error - Intentionally overriding parent method with different return type
24
- composeDetailed() {
25
- const _super = Object.create(null, {
26
- composeDetailed: { get: () => super.composeDetailed }
27
- });
62
+ compose(request = {}, requestOptions) {
63
+ return this._client.compose(request, requestOptions);
64
+ }
65
+ /**
66
+ * Compose a song from a prompt or a composition plan with detailed response parsing.
67
+ *
68
+ * Unlike the standard `compose()` method which returns a raw audio stream, this method
69
+ * automatically parses the multipart response to extract both the audio file and rich
70
+ * metadata about the generated composition.
71
+ *
72
+ * @param request - The music composition request containing either:
73
+ * - `prompt`: A text description of the desired music (e.g., "upbeat electronic dance music")
74
+ * - `compositionPlan`: A detailed composition plan object created via `compositionPlan.create()`
75
+ * - `musicLengthMs`: Optional duration in milliseconds (10000-300000ms)
76
+ *
77
+ * @param requestOptions - Optional request configuration (e.g., timeout, signal, headers)
78
+ *
79
+ * @returns A promise that resolves to a `MultipartResponse` containing:
80
+ * - `json.compositionPlan`: The detailed composition plan structure including sections,
81
+ * styles, and lyrics
82
+ * - `json.songMetadata`: Metadata about the generated song (title, description, genres,
83
+ * languages, explicit content flag)
84
+ * - `audio`: Buffer containing the complete audio file (MP3 format)
85
+ * - `filename`: Suggested filename for the audio file
86
+ *
87
+ * @throws {@link ElevenLabs.UnprocessableEntityError} If the request parameters are invalid
88
+ * or the music generation fails
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * const client = new ElevenLabs({ apiKey: "your-api-key" });
93
+ *
94
+ * // Generate music from a text prompt
95
+ * const response = await client.music.composeDetailed({
96
+ * prompt: "Epic orchestral music with dramatic strings and powerful brass",
97
+ * musicLengthMs: 60000 // 60 seconds
98
+ * });
99
+ *
100
+ * console.log("Title:", response.json.songMetadata.title);
101
+ * console.log("Genres:", response.json.songMetadata.genres);
102
+ *
103
+ * // Save the audio to a file
104
+ * fs.writeFileSync(response.filename, response.audio);
105
+ * ```
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * // Generate music from a composition plan
110
+ * const plan = await client.music.compositionPlan.create({
111
+ * prompt: "A progressive rock song about space exploration"
112
+ * });
113
+ *
114
+ * const response = await client.music.composeDetailed({
115
+ * compositionPlan: plan.compositionPlan
116
+ * });
117
+ *
118
+ * // Access detailed section information
119
+ * for (const section of response.json.compositionPlan.sections) {
120
+ * console.log(`${section.sectionName}: ${section.durationMs}ms`);
121
+ * }
122
+ * ```
123
+ */
124
+ composeDetailed(request = {}, requestOptions) {
125
+ return core.HttpResponsePromise.fromPromise(this._composeDetailed(request, requestOptions));
126
+ }
127
+ _composeDetailed() {
28
128
  return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
29
- // Call the parent method to get the stream
30
- const response = yield _super.composeDetailed.call(this, request, requestOptions);
31
- // Parse the stream using your existing parsing method
32
- const parsedResponse = yield this.parseMultipart(response);
33
- return parsedResponse;
129
+ // Call the base client method to get the stream with raw response
130
+ try {
131
+ const { data: stream, rawResponse } = yield this._client.composeDetailed(request, requestOptions).withRawResponse();
132
+ // Parse the stream using the existing parsing method
133
+ const parsedResponse = yield this.parseMultipart(stream);
134
+ return { data: parsedResponse, rawResponse };
135
+ }
136
+ catch (error) {
137
+ const message = error instanceof Error ? error.message : String(error);
138
+ throw new Error(`Failed to parse detailed composition response: ${message}`);
139
+ }
34
140
  });
35
141
  }
142
+ /**
143
+ * Stream a composed song from a prompt or a composition plan.
144
+ * @throws {@link ElevenLabs.UnprocessableEntityError}
145
+ */
146
+ stream(request = {}, requestOptions) {
147
+ return this._client.stream(request, requestOptions);
148
+ }
36
149
  /**
37
150
  * Reads a ReadableStream containing multipart data and parses it into JSON and audio parts
38
151
  * @param stream - ReadableStream from ElevenLabs music API response
@@ -98,7 +98,6 @@ class RealtimeConnection {
98
98
  break;
99
99
  case "final_transcript_with_timestamps":
100
100
  this.eventEmitter.emit(RealtimeEvents.FINAL_TRANSCRIPT_WITH_TIMESTAMPS, data);
101
- this.close();
102
101
  break;
103
102
  }
104
103
  });
@@ -44,6 +44,11 @@ interface BaseOptions {
44
44
  * Must be a valid model ID.
45
45
  */
46
46
  modelId: string;
47
+ /**
48
+ * An ISO-639-1 or ISO-639-3 language_code corresponding to the language of the audio file.
49
+ * Can sometimes improve transcription performance if known beforehand.
50
+ */
51
+ languageCode?: string;
47
52
  }
48
53
  export interface AudioOptions extends BaseOptions {
49
54
  audioFormat: AudioFormat;
@@ -133,6 +133,9 @@ class ScribeRealtime {
133
133
  }
134
134
  params.append("min_silence_duration_ms", options.minSilenceDurationMs.toString());
135
135
  }
136
+ if (options.languageCode !== undefined) {
137
+ params.append("language_code", options.languageCode);
138
+ }
136
139
  const queryString = params.toString();
137
140
  return queryString ? `${baseUri}?${queryString}` : baseUri;
138
141
  });