@elevenlabs/elevenlabs-js 2.19.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 +2 -2
- package/api/resources/conversationalAi/resources/agents/client/Client.d.ts +3 -5
- package/api/resources/conversationalAi/resources/agents/client/Client.js +11 -15
- package/api/resources/conversationalAi/resources/agents/client/requests/AgentsListRequest.d.ts +3 -0
- package/api/resources/conversationalAi/resources/agents/client/requests/index.d.ts +0 -1
- package/api/resources/studio/client/Client.d.ts +1 -0
- package/api/resources/studio/client/Client.js +18 -2
- package/api/resources/studio/client/requests/BodyCreatePodcastV1StudioPodcastsPost.d.ts +3 -0
- package/api/types/AgentDefinitionSource.d.ts +7 -0
- package/api/types/AgentDefinitionSource.js +10 -0
- package/api/types/AgentSummaryResponseModel.d.ts +2 -0
- package/api/types/ClientToolConfigInput.d.ts +2 -0
- package/api/types/ClientToolConfigOutput.d.ts +2 -0
- package/api/types/ConversationHistoryMetadataCommonModel.d.ts +3 -0
- package/api/types/CreateAgentResponseModel.d.ts +0 -4
- package/api/types/GetAgentResponseModel.d.ts +0 -2
- package/api/types/ProjectExtendedResponse.d.ts +2 -0
- package/api/types/ProjectResponse.d.ts +2 -0
- package/api/types/ToolExecutionMode.d.ts +6 -0
- package/api/types/ToolExecutionMode.js +9 -0
- package/api/types/WebhookToolConfigInput.d.ts +2 -0
- package/api/types/WebhookToolConfigOutput.d.ts +2 -0
- package/api/types/WhatsAppConversationInfo.d.ts +4 -0
- package/api/types/index.d.ts +3 -10
- package/api/types/index.js +3 -10
- package/dist/Client.js +2 -2
- package/dist/api/resources/conversationalAi/resources/agents/client/Client.d.ts +3 -5
- package/dist/api/resources/conversationalAi/resources/agents/client/Client.js +11 -15
- package/dist/api/resources/conversationalAi/resources/agents/client/requests/AgentsListRequest.d.ts +3 -0
- package/dist/api/resources/conversationalAi/resources/agents/client/requests/index.d.ts +0 -1
- package/dist/api/resources/studio/client/Client.d.ts +1 -0
- package/dist/api/resources/studio/client/Client.js +18 -2
- package/dist/api/resources/studio/client/requests/BodyCreatePodcastV1StudioPodcastsPost.d.ts +3 -0
- package/dist/api/types/AgentDefinitionSource.d.ts +7 -0
- package/dist/api/types/AgentDefinitionSource.js +10 -0
- package/dist/api/types/AgentSummaryResponseModel.d.ts +2 -0
- package/dist/api/types/ClientToolConfigInput.d.ts +2 -0
- package/dist/api/types/ClientToolConfigOutput.d.ts +2 -0
- package/dist/api/types/ConversationHistoryMetadataCommonModel.d.ts +3 -0
- package/dist/api/types/CreateAgentResponseModel.d.ts +0 -4
- package/dist/api/types/GetAgentResponseModel.d.ts +0 -2
- package/dist/api/types/ProjectExtendedResponse.d.ts +2 -0
- package/dist/api/types/ProjectResponse.d.ts +2 -0
- package/dist/api/types/ToolExecutionMode.d.ts +6 -0
- package/dist/api/types/ToolExecutionMode.js +9 -0
- package/dist/api/types/WebhookToolConfigInput.d.ts +2 -0
- package/dist/api/types/WebhookToolConfigOutput.d.ts +2 -0
- package/dist/api/types/WhatsAppConversationInfo.d.ts +4 -0
- package/dist/api/types/index.d.ts +3 -10
- package/dist/api/types/index.js +3 -10
- package/dist/serialization/resources/studio/client/requests/BodyCreatePodcastV1StudioPodcastsPost.d.ts +1 -1
- package/dist/serialization/types/AgentDefinitionSource.d.ts +7 -0
- package/dist/serialization/types/{WhatsAppChangeMessages.js → AgentDefinitionSource.js} +2 -2
- package/dist/serialization/types/AgentSummaryResponseModel.d.ts +1 -0
- package/dist/serialization/types/AgentSummaryResponseModel.js +1 -0
- package/dist/serialization/types/ClientToolConfigInput.d.ts +2 -0
- package/dist/serialization/types/ClientToolConfigInput.js +2 -0
- package/dist/serialization/types/ClientToolConfigOutput.d.ts +2 -0
- package/dist/serialization/types/ClientToolConfigOutput.js +2 -0
- package/dist/serialization/types/ConversationHistoryMetadataCommonModel.d.ts +5 -0
- package/dist/serialization/types/ConversationHistoryMetadataCommonModel.js +5 -0
- package/dist/serialization/types/CreateAgentResponseModel.d.ts +0 -2
- package/dist/serialization/types/CreateAgentResponseModel.js +0 -2
- package/dist/serialization/types/GetAgentResponseModel.d.ts +0 -1
- package/dist/serialization/types/GetAgentResponseModel.js +0 -1
- package/dist/serialization/types/ProjectExtendedResponse.d.ts +1 -0
- package/dist/serialization/types/ProjectExtendedResponse.js +1 -0
- package/dist/serialization/types/ProjectResponse.d.ts +1 -0
- package/dist/serialization/types/ProjectResponse.js +1 -0
- package/dist/serialization/types/ToolExecutionMode.d.ts +7 -0
- package/{serialization/types/WhatsAppCallDirection.js → dist/serialization/types/ToolExecutionMode.js} +2 -2
- package/dist/serialization/types/WebhookToolConfigInput.d.ts +2 -0
- package/dist/serialization/types/WebhookToolConfigInput.js +2 -0
- package/dist/serialization/types/WebhookToolConfigOutput.d.ts +2 -0
- package/dist/serialization/types/WebhookToolConfigOutput.js +2 -0
- package/dist/serialization/types/WhatsAppConversationInfo.d.ts +10 -0
- package/dist/serialization/types/{WhatsAppMetadata.js → WhatsAppConversationInfo.js} +4 -3
- package/dist/serialization/types/index.d.ts +3 -10
- package/dist/serialization/types/index.js +3 -10
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/wrapper/ElevenLabsClient.d.ts +3 -0
- package/dist/wrapper/ElevenLabsClient.js +8 -1
- package/dist/wrapper/index.d.ts +2 -0
- package/dist/wrapper/index.js +8 -1
- package/dist/wrapper/music.d.ts +74 -3
- package/dist/wrapper/music.js +127 -14
- package/dist/wrapper/realtime/connection.d.ts +179 -0
- package/dist/wrapper/realtime/connection.js +260 -0
- package/dist/wrapper/realtime/index.d.ts +2 -0
- package/dist/wrapper/realtime/index.js +10 -0
- package/dist/wrapper/realtime/scribe.d.ts +112 -0
- package/dist/wrapper/realtime/scribe.js +265 -0
- package/dist/wrapper/speechToText.d.ts +6 -0
- package/dist/wrapper/speechToText.js +14 -0
- package/package.json +11 -10
- package/reference.md +4 -12
- package/serialization/resources/studio/client/requests/BodyCreatePodcastV1StudioPodcastsPost.d.ts +1 -1
- package/serialization/types/AgentDefinitionSource.d.ts +7 -0
- package/serialization/types/{WhatsAppChangeMessages.js → AgentDefinitionSource.js} +2 -2
- package/serialization/types/AgentSummaryResponseModel.d.ts +1 -0
- package/serialization/types/AgentSummaryResponseModel.js +1 -0
- package/serialization/types/ClientToolConfigInput.d.ts +2 -0
- package/serialization/types/ClientToolConfigInput.js +2 -0
- package/serialization/types/ClientToolConfigOutput.d.ts +2 -0
- package/serialization/types/ClientToolConfigOutput.js +2 -0
- package/serialization/types/ConversationHistoryMetadataCommonModel.d.ts +5 -0
- package/serialization/types/ConversationHistoryMetadataCommonModel.js +5 -0
- package/serialization/types/CreateAgentResponseModel.d.ts +0 -2
- package/serialization/types/CreateAgentResponseModel.js +0 -2
- package/serialization/types/GetAgentResponseModel.d.ts +0 -1
- package/serialization/types/GetAgentResponseModel.js +0 -1
- package/serialization/types/ProjectExtendedResponse.d.ts +1 -0
- package/serialization/types/ProjectExtendedResponse.js +1 -0
- package/serialization/types/ProjectResponse.d.ts +1 -0
- package/serialization/types/ProjectResponse.js +1 -0
- package/serialization/types/ToolExecutionMode.d.ts +7 -0
- package/{dist/serialization/types/WhatsAppCallDirection.js → serialization/types/ToolExecutionMode.js} +2 -2
- package/serialization/types/WebhookToolConfigInput.d.ts +2 -0
- package/serialization/types/WebhookToolConfigInput.js +2 -0
- package/serialization/types/WebhookToolConfigOutput.d.ts +2 -0
- package/serialization/types/WebhookToolConfigOutput.js +2 -0
- package/serialization/types/WhatsAppConversationInfo.d.ts +10 -0
- package/{dist/serialization/types/WhatsAppChangeCalls.js → serialization/types/WhatsAppConversationInfo.js} +4 -4
- package/serialization/types/index.d.ts +3 -10
- package/serialization/types/index.js +3 -10
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/wrapper/ElevenLabsClient.d.ts +3 -0
- package/wrapper/ElevenLabsClient.js +8 -1
- package/wrapper/index.d.ts +2 -0
- package/wrapper/index.js +8 -1
- package/wrapper/music.d.ts +74 -3
- package/wrapper/music.js +127 -14
- package/wrapper/realtime/connection.d.ts +179 -0
- package/wrapper/realtime/connection.js +260 -0
- package/wrapper/realtime/index.d.ts +2 -0
- package/wrapper/realtime/index.js +10 -0
- package/wrapper/realtime/scribe.d.ts +112 -0
- package/wrapper/realtime/scribe.js +265 -0
- package/wrapper/speechToText.d.ts +6 -0
- package/wrapper/speechToText.js +14 -0
- package/api/resources/conversationalAi/resources/agents/client/requests/AgentsGetRequest.d.ts +0 -10
- package/api/types/WhatsAppBusinessAccount.d.ts +0 -5
- package/api/types/WhatsAppBusinessAccountChangesItem.d.ts +0 -10
- package/api/types/WhatsAppBusinessAccountChangesItem.js +0 -3
- package/api/types/WhatsAppCall.d.ts +0 -10
- package/api/types/WhatsAppCall.js +0 -3
- package/api/types/WhatsAppCallDirection.d.ts +0 -5
- package/api/types/WhatsAppCallDirection.js +0 -8
- package/api/types/WhatsAppCalls.d.ts +0 -5
- package/api/types/WhatsAppCalls.js +0 -3
- package/api/types/WhatsAppChangeCalls.d.ts +0 -4
- package/api/types/WhatsAppChangeCalls.js +0 -3
- package/api/types/WhatsAppChangeMessages.d.ts +0 -2
- package/api/types/WhatsAppChangeMessages.js +0 -3
- package/api/types/WhatsAppEventRequest.d.ts +0 -5
- package/api/types/WhatsAppEventRequest.js +0 -3
- package/api/types/WhatsAppMetadata.d.ts +0 -3
- package/api/types/WhatsAppMetadata.js +0 -3
- package/api/types/WhatsAppSession.d.ts +0 -4
- package/api/types/WhatsAppSession.js +0 -3
- package/dist/api/resources/conversationalAi/resources/agents/client/requests/AgentsGetRequest.d.ts +0 -10
- package/dist/api/resources/conversationalAi/resources/agents/client/requests/AgentsGetRequest.js +0 -3
- package/dist/api/types/WhatsAppBusinessAccount.d.ts +0 -5
- package/dist/api/types/WhatsAppBusinessAccount.js +0 -3
- package/dist/api/types/WhatsAppBusinessAccountChangesItem.d.ts +0 -10
- package/dist/api/types/WhatsAppBusinessAccountChangesItem.js +0 -3
- package/dist/api/types/WhatsAppCall.d.ts +0 -10
- package/dist/api/types/WhatsAppCall.js +0 -3
- package/dist/api/types/WhatsAppCallDirection.d.ts +0 -5
- package/dist/api/types/WhatsAppCallDirection.js +0 -8
- package/dist/api/types/WhatsAppCalls.d.ts +0 -5
- package/dist/api/types/WhatsAppCalls.js +0 -3
- package/dist/api/types/WhatsAppChangeCalls.d.ts +0 -4
- package/dist/api/types/WhatsAppChangeCalls.js +0 -3
- package/dist/api/types/WhatsAppChangeMessages.d.ts +0 -2
- package/dist/api/types/WhatsAppChangeMessages.js +0 -3
- package/dist/api/types/WhatsAppEventRequest.d.ts +0 -5
- package/dist/api/types/WhatsAppEventRequest.js +0 -3
- package/dist/api/types/WhatsAppMetadata.d.ts +0 -3
- package/dist/api/types/WhatsAppMetadata.js +0 -3
- package/dist/api/types/WhatsAppSession.d.ts +0 -4
- package/dist/api/types/WhatsAppSession.js +0 -3
- package/dist/serialization/types/WhatsAppBusinessAccount.d.ts +0 -11
- package/dist/serialization/types/WhatsAppBusinessAccount.js +0 -43
- package/dist/serialization/types/WhatsAppBusinessAccountChangesItem.d.ts +0 -15
- package/dist/serialization/types/WhatsAppBusinessAccountChangesItem.js +0 -49
- package/dist/serialization/types/WhatsAppCall.d.ts +0 -17
- package/dist/serialization/types/WhatsAppCall.js +0 -49
- package/dist/serialization/types/WhatsAppCallDirection.d.ts +0 -7
- package/dist/serialization/types/WhatsAppCalls.d.ts +0 -12
- package/dist/serialization/types/WhatsAppCalls.js +0 -44
- package/dist/serialization/types/WhatsAppChangeCalls.d.ts +0 -10
- package/dist/serialization/types/WhatsAppChangeMessages.d.ts +0 -8
- package/dist/serialization/types/WhatsAppEventRequest.d.ts +0 -11
- package/dist/serialization/types/WhatsAppEventRequest.js +0 -43
- package/dist/serialization/types/WhatsAppMetadata.d.ts +0 -9
- package/dist/serialization/types/WhatsAppSession.d.ts +0 -10
- package/dist/serialization/types/WhatsAppSession.js +0 -42
- package/serialization/types/WhatsAppBusinessAccount.d.ts +0 -11
- package/serialization/types/WhatsAppBusinessAccount.js +0 -43
- package/serialization/types/WhatsAppBusinessAccountChangesItem.d.ts +0 -15
- package/serialization/types/WhatsAppBusinessAccountChangesItem.js +0 -49
- package/serialization/types/WhatsAppCall.d.ts +0 -17
- package/serialization/types/WhatsAppCall.js +0 -49
- package/serialization/types/WhatsAppCallDirection.d.ts +0 -7
- package/serialization/types/WhatsAppCalls.d.ts +0 -12
- package/serialization/types/WhatsAppCalls.js +0 -44
- package/serialization/types/WhatsAppChangeCalls.d.ts +0 -10
- package/serialization/types/WhatsAppChangeCalls.js +0 -42
- package/serialization/types/WhatsAppChangeMessages.d.ts +0 -8
- package/serialization/types/WhatsAppEventRequest.d.ts +0 -11
- package/serialization/types/WhatsAppEventRequest.js +0 -43
- package/serialization/types/WhatsAppMetadata.d.ts +0 -9
- package/serialization/types/WhatsAppMetadata.js +0 -41
- package/serialization/types/WhatsAppSession.d.ts +0 -10
- package/serialization/types/WhatsAppSession.js +0 -42
- /package/api/{resources/conversationalAi/resources/agents/client/requests/AgentsGetRequest.js → types/WhatsAppConversationInfo.js} +0 -0
- /package/{api/types/WhatsAppBusinessAccount.js → dist/api/types/WhatsAppConversationInfo.js} +0 -0
|
@@ -38,6 +38,7 @@ const Client_1 = require("../Client");
|
|
|
38
38
|
const errors = __importStar(require("../errors"));
|
|
39
39
|
const webhooks_1 = require("./webhooks");
|
|
40
40
|
const music_1 = require("./music");
|
|
41
|
+
const speechToText_1 = require("./speechToText");
|
|
41
42
|
class ElevenLabsClient extends Client_1.ElevenLabsClient {
|
|
42
43
|
constructor(options = {}) {
|
|
43
44
|
var _a;
|
|
@@ -56,12 +57,18 @@ class ElevenLabsClient extends Client_1.ElevenLabsClient {
|
|
|
56
57
|
}
|
|
57
58
|
return this._customWebhooks;
|
|
58
59
|
}
|
|
59
|
-
// @ts-expect-error - Intentionally overriding
|
|
60
|
+
// @ts-expect-error - Intentionally overriding with wrapper Music that has enhanced composeDetailed
|
|
60
61
|
get music() {
|
|
61
62
|
if (!this._customMusic) {
|
|
62
63
|
this._customMusic = new music_1.Music(this._options);
|
|
63
64
|
}
|
|
64
65
|
return this._customMusic;
|
|
65
66
|
}
|
|
67
|
+
get speechToText() {
|
|
68
|
+
if (!this._customSpeechToText) {
|
|
69
|
+
this._customSpeechToText = new speechToText_1.SpeechToText(this._options);
|
|
70
|
+
}
|
|
71
|
+
return this._customSpeechToText;
|
|
72
|
+
}
|
|
66
73
|
}
|
|
67
74
|
exports.ElevenLabsClient = ElevenLabsClient;
|
package/dist/wrapper/index.d.ts
CHANGED
|
@@ -2,3 +2,5 @@ export { ElevenLabsClient } from "./ElevenLabsClient";
|
|
|
2
2
|
export { Music, type SongMetadata, type MultipartResponse } from "./music";
|
|
3
3
|
export { play } from "./play";
|
|
4
4
|
export { stream } from "./stream";
|
|
5
|
+
export { SpeechToText } from "./speechToText";
|
|
6
|
+
export { RealtimeConnection, RealtimeEvents, AudioFormat, CommitStrategy, type AudioOptions, type UrlOptions } from "./realtime";
|
package/dist/wrapper/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stream = exports.play = exports.Music = exports.ElevenLabsClient = void 0;
|
|
3
|
+
exports.CommitStrategy = exports.AudioFormat = exports.RealtimeEvents = exports.RealtimeConnection = exports.SpeechToText = exports.stream = exports.play = exports.Music = exports.ElevenLabsClient = void 0;
|
|
4
4
|
var ElevenLabsClient_1 = require("./ElevenLabsClient");
|
|
5
5
|
Object.defineProperty(exports, "ElevenLabsClient", { enumerable: true, get: function () { return ElevenLabsClient_1.ElevenLabsClient; } });
|
|
6
6
|
var music_1 = require("./music");
|
|
@@ -9,3 +9,10 @@ var play_1 = require("./play");
|
|
|
9
9
|
Object.defineProperty(exports, "play", { enumerable: true, get: function () { return play_1.play; } });
|
|
10
10
|
var stream_1 = require("./stream");
|
|
11
11
|
Object.defineProperty(exports, "stream", { enumerable: true, get: function () { return stream_1.stream; } });
|
|
12
|
+
var speechToText_1 = require("./speechToText");
|
|
13
|
+
Object.defineProperty(exports, "SpeechToText", { enumerable: true, get: function () { return speechToText_1.SpeechToText; } });
|
|
14
|
+
var realtime_1 = require("./realtime");
|
|
15
|
+
Object.defineProperty(exports, "RealtimeConnection", { enumerable: true, get: function () { return realtime_1.RealtimeConnection; } });
|
|
16
|
+
Object.defineProperty(exports, "RealtimeEvents", { enumerable: true, get: function () { return realtime_1.RealtimeEvents; } });
|
|
17
|
+
Object.defineProperty(exports, "AudioFormat", { enumerable: true, get: function () { return realtime_1.AudioFormat; } });
|
|
18
|
+
Object.defineProperty(exports, "CommitStrategy", { enumerable: true, get: function () { return realtime_1.CommitStrategy; } });
|
package/dist/wrapper/music.d.ts
CHANGED
|
@@ -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
|
|
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
|
-
*
|
|
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
|
-
|
|
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/dist/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
|
-
|
|
47
|
+
const core = __importStar(require("../core"));
|
|
48
|
+
class Music {
|
|
15
49
|
constructor(options = {}) {
|
|
16
|
-
|
|
50
|
+
this._client = new Client_1.Music(options);
|
|
17
51
|
}
|
|
18
52
|
/**
|
|
19
|
-
*
|
|
20
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import WebSocket from "ws";
|
|
2
|
+
import type { ChildProcess } from "node:child_process";
|
|
3
|
+
/**
|
|
4
|
+
* Events emitted by the RealtimeConnection.
|
|
5
|
+
*/
|
|
6
|
+
export declare enum RealtimeEvents {
|
|
7
|
+
/** Emitted when the session is successfully started */
|
|
8
|
+
SESSION_STARTED = "session_started",
|
|
9
|
+
/** Emitted when a partial (interim) transcript is available */
|
|
10
|
+
PARTIAL_TRANSCRIPT = "partial_transcript",
|
|
11
|
+
/** Emitted when a final transcript is available */
|
|
12
|
+
FINAL_TRANSCRIPT = "final_transcript",
|
|
13
|
+
/** Emitted when a final transcript with timestamps is available */
|
|
14
|
+
FINAL_TRANSCRIPT_WITH_TIMESTAMPS = "final_transcript_with_timestamps",
|
|
15
|
+
/** Emitted when an error occurs */
|
|
16
|
+
ERROR = "error",
|
|
17
|
+
/** Emitted when the WebSocket connection is opened */
|
|
18
|
+
OPEN = "open",
|
|
19
|
+
/** Emitted when the WebSocket connection is closed */
|
|
20
|
+
CLOSE = "close"
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Manages a real-time transcription WebSocket connection.
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* **Node.js only**: This class uses Node.js-specific WebSocket implementation.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const connection = await client.speechToText.realtime.connect({
|
|
31
|
+
* modelId: "scribe_realtime_v2",
|
|
32
|
+
* audioFormat: AudioFormat.PCM_16000,
|
|
33
|
+
* sampleRate: 16000,
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* connection.on(RealtimeEvents.SESSION_STARTED, (data) => {
|
|
37
|
+
* console.log("Session started");
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* connection.on(RealtimeEvents.PARTIAL_TRANSCRIPT, (data) => {
|
|
41
|
+
* console.log("Partial:", data.transcript);
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* connection.on(RealtimeEvents.FINAL_TRANSCRIPT, (data) => {
|
|
45
|
+
* console.log("Final:", data.transcript);
|
|
46
|
+
* connection.close();
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* // Send audio data
|
|
50
|
+
* connection.send({ audioBase64: base64String });
|
|
51
|
+
*
|
|
52
|
+
* // Commit and close
|
|
53
|
+
* connection.commit();
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare class RealtimeConnection {
|
|
57
|
+
private websocket;
|
|
58
|
+
private eventEmitter;
|
|
59
|
+
private ffmpegProcess;
|
|
60
|
+
private currentSampleRate;
|
|
61
|
+
constructor(sampleRate: number);
|
|
62
|
+
/**
|
|
63
|
+
* @internal
|
|
64
|
+
* Used internally by ScribeRealtime to attach the WebSocket after connection is created.
|
|
65
|
+
*/
|
|
66
|
+
setWebSocket(websocket: WebSocket): void;
|
|
67
|
+
/**
|
|
68
|
+
* @internal
|
|
69
|
+
* Used internally by ScribeRealtime to attach ffmpeg process for cleanup.
|
|
70
|
+
*/
|
|
71
|
+
setFfmpegProcess(ffmpegProcess: ChildProcess): void;
|
|
72
|
+
/**
|
|
73
|
+
* Attaches an event listener for the specified event.
|
|
74
|
+
*
|
|
75
|
+
* @param event - The event to listen for (use RealtimeEvents enum)
|
|
76
|
+
* @param listener - The callback function to execute when the event fires
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* connection.on(RealtimeEvents.SESSION_STARTED, (data) => {
|
|
81
|
+
* console.log("Session started", data);
|
|
82
|
+
* });
|
|
83
|
+
*
|
|
84
|
+
* connection.on(RealtimeEvents.PARTIAL_TRANSCRIPT, (data) => {
|
|
85
|
+
* console.log("Partial:", data.transcript);
|
|
86
|
+
* });
|
|
87
|
+
*
|
|
88
|
+
* connection.on(RealtimeEvents.FINAL_TRANSCRIPT, (data) => {
|
|
89
|
+
* console.log("Final:", data.transcript);
|
|
90
|
+
* });
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
on(event: RealtimeEvents, listener: (...args: unknown[]) => void): void;
|
|
94
|
+
/**
|
|
95
|
+
* Removes an event listener for the specified event.
|
|
96
|
+
*
|
|
97
|
+
* @param event - The event to stop listening for
|
|
98
|
+
* @param listener - The callback function to remove
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const handler = (data) => console.log(data);
|
|
103
|
+
* connection.on(RealtimeEvents.PARTIAL_TRANSCRIPT, handler);
|
|
104
|
+
*
|
|
105
|
+
* // Later, remove the listener
|
|
106
|
+
* connection.off(RealtimeEvents.PARTIAL_TRANSCRIPT, handler);
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
off(event: RealtimeEvents, listener: (...args: unknown[]) => void): void;
|
|
110
|
+
/**
|
|
111
|
+
* Sends audio data to the transcription service.
|
|
112
|
+
*
|
|
113
|
+
* @param data - Audio data configuration
|
|
114
|
+
* @param data.audioBase64 - Base64-encoded audio data
|
|
115
|
+
* @param data.commit - Whether to commit the transcription after this chunk. You likely want to use connection.commit() instead (default: false)
|
|
116
|
+
* @param data.sampleRate - Sample rate of the audio (default: configured sample rate)
|
|
117
|
+
*
|
|
118
|
+
* @throws {Error} If the WebSocket connection is not open
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* // Send audio chunk without committing
|
|
123
|
+
* connection.send({
|
|
124
|
+
* audioBase64: base64EncodedAudio,
|
|
125
|
+
* });
|
|
126
|
+
*
|
|
127
|
+
* // Send audio chunk with custom sample rate
|
|
128
|
+
* connection.send({
|
|
129
|
+
* audioBase64: base64EncodedAudio,
|
|
130
|
+
* sampleRate: 16000,
|
|
131
|
+
* });
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
send(data: {
|
|
135
|
+
audioBase64: string;
|
|
136
|
+
commit?: boolean;
|
|
137
|
+
sampleRate?: number;
|
|
138
|
+
}): void;
|
|
139
|
+
/**
|
|
140
|
+
* Commits the transcription, signaling that all audio has been sent.
|
|
141
|
+
* This finalizes the transcription and triggers a FINAL_TRANSCRIPT event.
|
|
142
|
+
*
|
|
143
|
+
* @throws {Error} If the WebSocket connection is not open
|
|
144
|
+
*
|
|
145
|
+
* @remarks
|
|
146
|
+
* Only needed when using CommitStrategy.MANUAL.
|
|
147
|
+
* When using CommitStrategy.VAD, commits are handled automatically by the server.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* // Send all audio chunks
|
|
152
|
+
* for (const chunk of audioChunks) {
|
|
153
|
+
* connection.send({ audioBase64: chunk });
|
|
154
|
+
* }
|
|
155
|
+
*
|
|
156
|
+
* // Finalize the transcription
|
|
157
|
+
* connection.commit();
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
commit(): void;
|
|
161
|
+
/**
|
|
162
|
+
* Closes the WebSocket connection and cleans up resources.
|
|
163
|
+
* This will terminate any ongoing transcription and stop ffmpeg processes if running.
|
|
164
|
+
*
|
|
165
|
+
* @remarks
|
|
166
|
+
* After calling close(), this connection cannot be reused.
|
|
167
|
+
* Create a new connection if you need to start transcribing again.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* connection.on(RealtimeEvents.FINAL_TRANSCRIPT, (data) => {
|
|
172
|
+
* console.log("Final:", data.transcript);
|
|
173
|
+
* connection.close();
|
|
174
|
+
* });
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
close(): void;
|
|
178
|
+
private cleanup;
|
|
179
|
+
}
|