@speech-sdk/core 0.0.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/README.md +185 -0
- package/dist/errors.d.ts +20 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +25 -0
- package/dist/errors.js.map +1 -0
- package/dist/generate-speech.d.ts +12 -0
- package/dist/generate-speech.d.ts.map +1 -0
- package/dist/generate-speech.js +39 -0
- package/dist/generate-speech.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/provider-utils.d.ts +3 -0
- package/dist/provider-utils.d.ts.map +1 -0
- package/dist/provider-utils.js +49 -0
- package/dist/provider-utils.js.map +1 -0
- package/dist/providers/cartesia/index.d.ts +35 -0
- package/dist/providers/cartesia/index.d.ts.map +1 -0
- package/dist/providers/cartesia/index.js +59 -0
- package/dist/providers/cartesia/index.js.map +1 -0
- package/dist/providers/deepgram/index.d.ts +32 -0
- package/dist/providers/deepgram/index.d.ts.map +1 -0
- package/dist/providers/deepgram/index.js +53 -0
- package/dist/providers/deepgram/index.js.map +1 -0
- package/dist/providers/elevenlabs/elevenlabs-options.d.ts +2 -0
- package/dist/providers/elevenlabs/elevenlabs-options.d.ts.map +1 -0
- package/dist/providers/elevenlabs/elevenlabs-options.js +2 -0
- package/dist/providers/elevenlabs/elevenlabs-options.js.map +1 -0
- package/dist/providers/elevenlabs/elevenlabs-provider.d.ts +5 -0
- package/dist/providers/elevenlabs/elevenlabs-provider.d.ts.map +1 -0
- package/dist/providers/elevenlabs/elevenlabs-provider.js +11 -0
- package/dist/providers/elevenlabs/elevenlabs-provider.js.map +1 -0
- package/dist/providers/elevenlabs/elevenlabs-speech-model.d.ts +44 -0
- package/dist/providers/elevenlabs/elevenlabs-speech-model.d.ts.map +1 -0
- package/dist/providers/elevenlabs/elevenlabs-speech-model.js +82 -0
- package/dist/providers/elevenlabs/elevenlabs-speech-model.js.map +1 -0
- package/dist/providers/elevenlabs/index.d.ts +44 -0
- package/dist/providers/elevenlabs/index.d.ts.map +1 -0
- package/dist/providers/elevenlabs/index.js +91 -0
- package/dist/providers/elevenlabs/index.js.map +1 -0
- package/dist/providers/fal/index.d.ts +35 -0
- package/dist/providers/fal/index.d.ts.map +1 -0
- package/dist/providers/fal/index.js +70 -0
- package/dist/providers/fal/index.js.map +1 -0
- package/dist/providers/fish-audio/index.d.ts +32 -0
- package/dist/providers/fish-audio/index.d.ts.map +1 -0
- package/dist/providers/fish-audio/index.js +54 -0
- package/dist/providers/fish-audio/index.js.map +1 -0
- package/dist/providers/google/index.d.ts +35 -0
- package/dist/providers/google/index.d.ts.map +1 -0
- package/dist/providers/google/index.js +71 -0
- package/dist/providers/google/index.js.map +1 -0
- package/dist/providers/hume/index.d.ts +36 -0
- package/dist/providers/hume/index.d.ts.map +1 -0
- package/dist/providers/hume/index.js +66 -0
- package/dist/providers/hume/index.js.map +1 -0
- package/dist/providers/mistral/index.d.ts +37 -0
- package/dist/providers/mistral/index.d.ts.map +1 -0
- package/dist/providers/mistral/index.js +66 -0
- package/dist/providers/mistral/index.js.map +1 -0
- package/dist/providers/murf/index.d.ts +35 -0
- package/dist/providers/murf/index.d.ts.map +1 -0
- package/dist/providers/murf/index.js +68 -0
- package/dist/providers/murf/index.js.map +1 -0
- package/dist/providers/openai/index.d.ts +39 -0
- package/dist/providers/openai/index.d.ts.map +1 -0
- package/dist/providers/openai/index.js +63 -0
- package/dist/providers/openai/index.js.map +1 -0
- package/dist/providers/openai/openai-options.d.ts +2 -0
- package/dist/providers/openai/openai-options.d.ts.map +1 -0
- package/dist/providers/openai/openai-options.js +2 -0
- package/dist/providers/openai/openai-options.js.map +1 -0
- package/dist/providers/openai/openai-provider.d.ts +5 -0
- package/dist/providers/openai/openai-provider.d.ts.map +1 -0
- package/dist/providers/openai/openai-provider.js +11 -0
- package/dist/providers/openai/openai-provider.js.map +1 -0
- package/dist/providers/openai/openai-speech-model.d.ts +39 -0
- package/dist/providers/openai/openai-speech-model.d.ts.map +1 -0
- package/dist/providers/openai/openai-speech-model.js +54 -0
- package/dist/providers/openai/openai-speech-model.js.map +1 -0
- package/dist/providers/resemble/index.d.ts +32 -0
- package/dist/providers/resemble/index.d.ts.map +1 -0
- package/dist/providers/resemble/index.js +50 -0
- package/dist/providers/resemble/index.js.map +1 -0
- package/dist/providers/unreal-speech/index.d.ts +32 -0
- package/dist/providers/unreal-speech/index.d.ts.map +1 -0
- package/dist/providers/unreal-speech/index.js +64 -0
- package/dist/providers/unreal-speech/index.js.map +1 -0
- package/dist/resolve-provider.d.ts +3 -0
- package/dist/resolve-provider.d.ts.map +1 -0
- package/dist/resolve-provider.js +71 -0
- package/dist/resolve-provider.js.map +1 -0
- package/dist/speech-provider.d.ts +31 -0
- package/dist/speech-provider.d.ts.map +1 -0
- package/dist/speech-provider.js +2 -0
- package/dist/speech-provider.js.map +1 -0
- package/dist/speech-result.d.ts +22 -0
- package/dist/speech-result.d.ts.map +1 -0
- package/dist/speech-result.js +42 -0
- package/dist/speech-result.js.map +1 -0
- package/dist/types.d.ts +11 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +96 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { SpeechProvider } from '../../speech-provider.js';
|
|
2
|
+
import type { ElevenLabsSpeechOptions } from './elevenlabs-options.js';
|
|
3
|
+
export interface ElevenLabsSpeechProviderConfig {
|
|
4
|
+
apiKey?: string;
|
|
5
|
+
baseURL?: string;
|
|
6
|
+
fetch?: typeof globalThis.fetch;
|
|
7
|
+
}
|
|
8
|
+
export declare class ElevenLabsSpeechProvider implements SpeechProvider<string, ElevenLabsSpeechOptions> {
|
|
9
|
+
readonly id = "elevenlabs";
|
|
10
|
+
readonly defaultModel = "eleven_multilingual_v2";
|
|
11
|
+
private static readonly V2_LANGUAGES;
|
|
12
|
+
private static readonly FLASH_V2_5_LANGUAGES;
|
|
13
|
+
private static readonly V3_LANGUAGES;
|
|
14
|
+
readonly models: readonly [{
|
|
15
|
+
readonly id: "eleven_v3";
|
|
16
|
+
readonly languages: readonly ["af", "ar", "hy", "as", "az", "be", "bn", "bs", "bg", "ca", "ceb", "ny", "hr", "cs", "da", "nl", "en", "et", "fil", "fi", "fr", "gl", "ka", "de", "el", "gu", "ha", "he", "hi", "hu", "is", "id", "ga", "it", "ja", "jv", "kn", "kk", "ky", "ko", "lv", "ln", "lt", "lb", "mk", "ms", "ml", "zh", "mr", "ne", "no", "ps", "fa", "pl", "pt", "pa", "ro", "ru", "sr", "sd", "sk", "sl", "so", "es", "sw", "sv", "ta", "te", "th", "tr", "uk", "ur", "vi", "cy"];
|
|
17
|
+
}, {
|
|
18
|
+
readonly id: "eleven_multilingual_v2";
|
|
19
|
+
readonly languages: readonly ["ar", "bg", "cs", "da", "de", "el", "en", "es", "fi", "fil", "fr", "he", "hi", "hr", "id", "it", "ja", "ko", "ms", "nl", "pl", "pt", "ro", "ru", "sk", "sv", "ta", "uk", "zh"];
|
|
20
|
+
}, {
|
|
21
|
+
readonly id: "eleven_flash_v2_5";
|
|
22
|
+
readonly languages: readonly ["ar", "bg", "cs", "da", "de", "el", "en", "es", "fi", "fil", "fr", "he", "hi", "hr", "id", "it", "ja", "ko", "ms", "nl", "pl", "pt", "ro", "ru", "sk", "sv", "ta", "uk", "zh", "hu", "no", "vi"];
|
|
23
|
+
}, {
|
|
24
|
+
readonly id: "eleven_flash_v2";
|
|
25
|
+
readonly languages: readonly ["en"];
|
|
26
|
+
}];
|
|
27
|
+
private readonly apiKey;
|
|
28
|
+
private readonly baseURL;
|
|
29
|
+
private readonly fetchFn;
|
|
30
|
+
constructor(config: ElevenLabsSpeechProviderConfig);
|
|
31
|
+
generate(options: {
|
|
32
|
+
modelId: string;
|
|
33
|
+
text: string;
|
|
34
|
+
voice?: string;
|
|
35
|
+
providerOptions?: ElevenLabsSpeechOptions;
|
|
36
|
+
abortSignal?: AbortSignal;
|
|
37
|
+
headers?: Record<string, string>;
|
|
38
|
+
}): Promise<{
|
|
39
|
+
audio: Uint8Array;
|
|
40
|
+
mediaType: string;
|
|
41
|
+
providerMetadata?: Record<string, unknown>;
|
|
42
|
+
}>;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=elevenlabs-speech-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elevenlabs-speech-model.d.ts","sourceRoot":"","sources":["../../../src/providers/elevenlabs/elevenlabs-speech-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG/D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAEvE,MAAM,WAAW,8BAA8B;IAC7C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC;AAED,qBAAa,wBACX,YAAW,cAAc,CAAC,MAAM,EAAE,uBAAuB,CAAC;IAE1D,QAAQ,CAAC,EAAE,gBAAgB;IAC3B,QAAQ,CAAC,YAAY,4BAA4B;IAEjD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAIzB;IAEX,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,oBAAoB,CAEjC;IAEX,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CASzB;IAEX,QAAQ,CAAC,MAAM;;;;;;;;;;;;OAKJ;IAEX,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAC5C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA0B;gBAEtC,MAAM,EAAE,8BAA8B;IAM5C,QAAQ,CAAC,OAAO,EAAE;QACtB,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,eAAe,CAAC,EAAE,uBAAuB,CAAC;QAC1C,WAAW,CAAC,EAAE,WAAW,CAAC;QAC1B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAClC,GAAG,OAAO,CAAC;QACV,KAAK,EAAE,UAAU,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC5C,CAAC;CAkDH"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { SpeechSDKError } from '../../errors.js';
|
|
2
|
+
import { resolveApiKey, handleErrorResponse } from '../../provider-utils.js';
|
|
3
|
+
export class ElevenLabsSpeechProvider {
|
|
4
|
+
id = 'elevenlabs';
|
|
5
|
+
defaultModel = 'eleven_multilingual_v2';
|
|
6
|
+
static V2_LANGUAGES = [
|
|
7
|
+
'ar', 'bg', 'cs', 'da', 'de', 'el', 'en', 'es', 'fi', 'fil',
|
|
8
|
+
'fr', 'he', 'hi', 'hr', 'id', 'it', 'ja', 'ko', 'ms',
|
|
9
|
+
'nl', 'pl', 'pt', 'ro', 'ru', 'sk', 'sv', 'ta', 'uk', 'zh',
|
|
10
|
+
];
|
|
11
|
+
static FLASH_V2_5_LANGUAGES = [
|
|
12
|
+
...ElevenLabsSpeechProvider.V2_LANGUAGES, 'hu', 'no', 'vi',
|
|
13
|
+
];
|
|
14
|
+
static V3_LANGUAGES = [
|
|
15
|
+
'af', 'ar', 'hy', 'as', 'az', 'be', 'bn', 'bs', 'bg', 'ca',
|
|
16
|
+
'ceb', 'ny', 'hr', 'cs', 'da', 'nl', 'en', 'et', 'fil', 'fi',
|
|
17
|
+
'fr', 'gl', 'ka', 'de', 'el', 'gu', 'ha', 'he', 'hi', 'hu',
|
|
18
|
+
'is', 'id', 'ga', 'it', 'ja', 'jv', 'kn', 'kk', 'ky', 'ko',
|
|
19
|
+
'lv', 'ln', 'lt', 'lb', 'mk', 'ms', 'ml', 'zh', 'mr', 'ne',
|
|
20
|
+
'no', 'ps', 'fa', 'pl', 'pt', 'pa', 'ro', 'ru', 'sr', 'sd',
|
|
21
|
+
'sk', 'sl', 'so', 'es', 'sw', 'sv', 'ta', 'te', 'th', 'tr',
|
|
22
|
+
'uk', 'ur', 'vi', 'cy',
|
|
23
|
+
];
|
|
24
|
+
models = [
|
|
25
|
+
{ id: 'eleven_v3', languages: ElevenLabsSpeechProvider.V3_LANGUAGES },
|
|
26
|
+
{ id: 'eleven_multilingual_v2', languages: ElevenLabsSpeechProvider.V2_LANGUAGES },
|
|
27
|
+
{ id: 'eleven_flash_v2_5', languages: ElevenLabsSpeechProvider.FLASH_V2_5_LANGUAGES },
|
|
28
|
+
{ id: 'eleven_flash_v2', languages: ['en'] },
|
|
29
|
+
];
|
|
30
|
+
apiKey;
|
|
31
|
+
baseURL;
|
|
32
|
+
fetchFn;
|
|
33
|
+
constructor(config) {
|
|
34
|
+
this.apiKey = config.apiKey;
|
|
35
|
+
this.baseURL = config.baseURL ?? 'https://api.elevenlabs.io';
|
|
36
|
+
this.fetchFn = config.fetch ?? globalThis.fetch;
|
|
37
|
+
}
|
|
38
|
+
async generate(options) {
|
|
39
|
+
if (!options.voice) {
|
|
40
|
+
throw new SpeechSDKError('ElevenLabs requires a voice ID. Pass it via the voice option.');
|
|
41
|
+
}
|
|
42
|
+
const providerOptions = options.providerOptions ?? {};
|
|
43
|
+
const { output_format, enable_logging, optimize_streaming_latency, ...bodyOptions } = providerOptions;
|
|
44
|
+
const body = {
|
|
45
|
+
...bodyOptions,
|
|
46
|
+
text: options.text,
|
|
47
|
+
model_id: options.modelId,
|
|
48
|
+
};
|
|
49
|
+
const queryParams = new URLSearchParams();
|
|
50
|
+
if (output_format != null)
|
|
51
|
+
queryParams.set('output_format', String(output_format));
|
|
52
|
+
if (enable_logging != null)
|
|
53
|
+
queryParams.set('enable_logging', String(enable_logging));
|
|
54
|
+
if (optimize_streaming_latency != null)
|
|
55
|
+
queryParams.set('optimize_streaming_latency', String(optimize_streaming_latency));
|
|
56
|
+
let url = `${this.baseURL}/v1/text-to-speech/${options.voice}`;
|
|
57
|
+
const queryString = queryParams.toString();
|
|
58
|
+
if (queryString) {
|
|
59
|
+
url += `?${queryString}`;
|
|
60
|
+
}
|
|
61
|
+
const response = await this.fetchFn(url, {
|
|
62
|
+
method: 'POST',
|
|
63
|
+
headers: {
|
|
64
|
+
'Content-Type': 'application/json',
|
|
65
|
+
'xi-api-key': resolveApiKey(this.apiKey, 'ELEVENLABS_API_KEY', 'ElevenLabs'),
|
|
66
|
+
...options.headers,
|
|
67
|
+
},
|
|
68
|
+
body: JSON.stringify(body),
|
|
69
|
+
signal: options.abortSignal,
|
|
70
|
+
});
|
|
71
|
+
await handleErrorResponse(response, `elevenlabs/${options.modelId}`);
|
|
72
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
73
|
+
const mediaType = response.headers.get('content-type') ?? 'audio/mpeg';
|
|
74
|
+
const requestId = response.headers.get('request-id');
|
|
75
|
+
return {
|
|
76
|
+
audio: new Uint8Array(arrayBuffer),
|
|
77
|
+
mediaType,
|
|
78
|
+
providerMetadata: requestId ? { requestId } : undefined,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=elevenlabs-speech-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elevenlabs-speech-model.js","sourceRoot":"","sources":["../../../src/providers/elevenlabs/elevenlabs-speech-model.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAS7E,MAAM,OAAO,wBAAwB;IAG1B,EAAE,GAAG,YAAY,CAAC;IAClB,YAAY,GAAG,wBAAwB,CAAC;IAEzC,M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I,YAAY,CAAC;QACvE,MAAM,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAErD,OAAO;YACL,KAAK,EAAE,IAAI,UAAU,CAAC,WAAW,CAAC;YAClC,SAAS;YACT,gBAAgB,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,SAAS;SACxD,CAAC;IACJ,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { SpeechProvider, ResolvedModel } from '../../speech-provider.js';
|
|
2
|
+
export interface ElevenLabsSpeechProviderConfig {
|
|
3
|
+
apiKey?: string;
|
|
4
|
+
baseURL?: string;
|
|
5
|
+
fetch?: typeof globalThis.fetch;
|
|
6
|
+
}
|
|
7
|
+
export declare class ElevenLabsSpeechProvider implements SpeechProvider<string, string> {
|
|
8
|
+
readonly id = "elevenlabs";
|
|
9
|
+
readonly defaultModel = "eleven_multilingual_v2";
|
|
10
|
+
private static readonly V2_LANGUAGES;
|
|
11
|
+
private static readonly FLASH_V2_5_LANGUAGES;
|
|
12
|
+
private static readonly V3_LANGUAGES;
|
|
13
|
+
readonly models: readonly [{
|
|
14
|
+
readonly id: "eleven_v3";
|
|
15
|
+
readonly languages: readonly ["af", "ar", "hy", "as", "az", "be", "bn", "bs", "bg", "ca", "ceb", "ny", "hr", "cs", "da", "nl", "en", "et", "fil", "fi", "fr", "gl", "ka", "de", "el", "gu", "ha", "he", "hi", "hu", "is", "id", "ga", "it", "ja", "jv", "kn", "kk", "ky", "ko", "lv", "ln", "lt", "lb", "mk", "ms", "ml", "zh", "mr", "ne", "no", "ps", "fa", "pl", "pt", "pa", "ro", "ru", "sr", "sd", "sk", "sl", "so", "es", "sw", "sv", "ta", "te", "th", "tr", "uk", "ur", "vi", "cy"];
|
|
16
|
+
}, {
|
|
17
|
+
readonly id: "eleven_multilingual_v2";
|
|
18
|
+
readonly languages: readonly ["ar", "bg", "cs", "da", "de", "el", "en", "es", "fi", "fil", "fr", "he", "hi", "hr", "id", "it", "ja", "ko", "ms", "nl", "pl", "pt", "ro", "ru", "sk", "sv", "ta", "uk", "zh"];
|
|
19
|
+
}, {
|
|
20
|
+
readonly id: "eleven_flash_v2_5";
|
|
21
|
+
readonly languages: readonly ["ar", "bg", "cs", "da", "de", "el", "en", "es", "fi", "fil", "fr", "he", "hi", "hr", "id", "it", "ja", "ko", "ms", "nl", "pl", "pt", "ro", "ru", "sk", "sv", "ta", "uk", "zh", "hu", "no", "vi"];
|
|
22
|
+
}, {
|
|
23
|
+
readonly id: "eleven_flash_v2";
|
|
24
|
+
readonly languages: readonly ["en"];
|
|
25
|
+
}];
|
|
26
|
+
private readonly apiKey;
|
|
27
|
+
private readonly baseURL;
|
|
28
|
+
private readonly fetchFn;
|
|
29
|
+
constructor(config: ElevenLabsSpeechProviderConfig);
|
|
30
|
+
generate(options: {
|
|
31
|
+
modelId: string;
|
|
32
|
+
text: string;
|
|
33
|
+
voice?: string;
|
|
34
|
+
providerOptions?: Record<string, unknown>;
|
|
35
|
+
abortSignal?: AbortSignal;
|
|
36
|
+
headers?: Record<string, string>;
|
|
37
|
+
}): Promise<{
|
|
38
|
+
audio: Uint8Array;
|
|
39
|
+
mediaType: string;
|
|
40
|
+
providerMetadata?: Record<string, unknown>;
|
|
41
|
+
}>;
|
|
42
|
+
}
|
|
43
|
+
export declare function createElevenLabs(config?: ElevenLabsSpeechProviderConfig): (modelId?: string) => ResolvedModel<string>;
|
|
44
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/elevenlabs/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAI9E,MAAM,WAAW,8BAA8B;IAC7C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,C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ApiKey, handleErrorResponse } from '../../provider-utils.js';
|
|
3
|
+
export class ElevenLabsSpeechProvider {
|
|
4
|
+
id = 'elevenlabs';
|
|
5
|
+
defaultModel = 'eleven_multilingual_v2';
|
|
6
|
+
static V2_LANGUAGES = [
|
|
7
|
+
'ar', 'bg', 'cs', 'da', 'de', 'el', 'en', 'es', 'fi', 'fil',
|
|
8
|
+
'fr', 'he', 'hi', 'hr', 'id', 'it', 'ja', 'ko', 'ms',
|
|
9
|
+
'nl', 'pl', 'pt', 'ro', 'ru', 'sk', 'sv', 'ta', 'uk', 'zh',
|
|
10
|
+
];
|
|
11
|
+
static FLASH_V2_5_LANGUAGES = [
|
|
12
|
+
...ElevenLabsSpeechProvider.V2_LANGUAGES, 'hu', 'no', 'vi',
|
|
13
|
+
];
|
|
14
|
+
static V3_LANGUAGES = [
|
|
15
|
+
'af', 'ar', 'hy', 'as', 'az', 'be', 'bn', 'bs', 'bg', 'ca',
|
|
16
|
+
'ceb', 'ny', 'hr', 'cs', 'da', 'nl', 'en', 'et', 'fil', 'fi',
|
|
17
|
+
'fr', 'gl', 'ka', 'de', 'el', 'gu', 'ha', 'he', 'hi', 'hu',
|
|
18
|
+
'is', 'id', 'ga', 'it', 'ja', 'jv', 'kn', 'kk', 'ky', 'ko',
|
|
19
|
+
'lv', 'ln', 'lt', 'lb', 'mk', 'ms', 'ml', 'zh', 'mr', 'ne',
|
|
20
|
+
'no', 'ps', 'fa', 'pl', 'pt', 'pa', 'ro', 'ru', 'sr', 'sd',
|
|
21
|
+
'sk', 'sl', 'so', 'es', 'sw', 'sv', 'ta', 'te', 'th', 'tr',
|
|
22
|
+
'uk', 'ur', 'vi', 'cy',
|
|
23
|
+
];
|
|
24
|
+
models = [
|
|
25
|
+
{ id: 'eleven_v3', languages: ElevenLabsSpeechProvider.V3_LANGUAGES },
|
|
26
|
+
{ id: 'eleven_multilingual_v2', languages: ElevenLabsSpeechProvider.V2_LANGUAGES },
|
|
27
|
+
{ id: 'eleven_flash_v2_5', languages: ElevenLabsSpeechProvider.FLASH_V2_5_LANGUAGES },
|
|
28
|
+
{ id: 'eleven_flash_v2', languages: ['en'] },
|
|
29
|
+
];
|
|
30
|
+
apiKey;
|
|
31
|
+
baseURL;
|
|
32
|
+
fetchFn;
|
|
33
|
+
constructor(config) {
|
|
34
|
+
this.apiKey = config.apiKey;
|
|
35
|
+
this.baseURL = config.baseURL ?? 'https://api.elevenlabs.io';
|
|
36
|
+
this.fetchFn = config.fetch ?? globalThis.fetch;
|
|
37
|
+
}
|
|
38
|
+
async generate(options) {
|
|
39
|
+
if (!options.voice) {
|
|
40
|
+
throw new SpeechSDKError('ElevenLabs requires a voice ID. Pass it via the voice option.');
|
|
41
|
+
}
|
|
42
|
+
const providerOptions = options.providerOptions ?? {};
|
|
43
|
+
const { output_format, enable_logging, optimize_streaming_latency, ...bodyOptions } = providerOptions;
|
|
44
|
+
const body = {
|
|
45
|
+
...bodyOptions,
|
|
46
|
+
text: options.text,
|
|
47
|
+
model_id: options.modelId,
|
|
48
|
+
};
|
|
49
|
+
const queryParams = new URLSearchParams();
|
|
50
|
+
if (output_format != null)
|
|
51
|
+
queryParams.set('output_format', String(output_format));
|
|
52
|
+
if (enable_logging != null)
|
|
53
|
+
queryParams.set('enable_logging', String(enable_logging));
|
|
54
|
+
if (optimize_streaming_latency != null)
|
|
55
|
+
queryParams.set('optimize_streaming_latency', String(optimize_streaming_latency));
|
|
56
|
+
let url = `${this.baseURL}/v1/text-to-speech/${options.voice}`;
|
|
57
|
+
const queryString = queryParams.toString();
|
|
58
|
+
if (queryString) {
|
|
59
|
+
url += `?${queryString}`;
|
|
60
|
+
}
|
|
61
|
+
const response = await this.fetchFn(url, {
|
|
62
|
+
method: 'POST',
|
|
63
|
+
headers: {
|
|
64
|
+
'Content-Type': 'application/json',
|
|
65
|
+
'xi-api-key': resolveApiKey(this.apiKey, 'ELEVENLABS_API_KEY', 'ElevenLabs'),
|
|
66
|
+
...options.headers,
|
|
67
|
+
},
|
|
68
|
+
body: JSON.stringify(body),
|
|
69
|
+
signal: options.abortSignal,
|
|
70
|
+
});
|
|
71
|
+
await handleErrorResponse(response, `elevenlabs/${options.modelId}`);
|
|
72
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
73
|
+
const mediaType = response.headers.get('content-type') ?? 'audio/mpeg';
|
|
74
|
+
const requestId = response.headers.get('request-id');
|
|
75
|
+
return {
|
|
76
|
+
audio: new Uint8Array(arrayBuffer),
|
|
77
|
+
mediaType,
|
|
78
|
+
providerMetadata: requestId ? { requestId } : undefined,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export function createElevenLabs(config = {}) {
|
|
83
|
+
const provider = new ElevenLabsSpeechProvider(config);
|
|
84
|
+
return function elevenlabs(modelId) {
|
|
85
|
+
return {
|
|
86
|
+
provider,
|
|
87
|
+
modelId: modelId ?? provider.defaultModel,
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/providers/elevenlabs/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAQ7E,MAAM,OAAO,wBAAwB;IAG1B,EAAE,GAAG,YAAY,CAAC;IAClB,YAAY,GAAG,wBAAwB,CAAC;IAEzC,MAAM,CAAU,YAAY,GAAG;QACrC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK;QAC3D,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;QACpD,IAAI,EAAE,IAAI,E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GH,MAAM,UAAU,gBAAgB,CAAC,SAAyC,EAAE;IAC1E,MAAM,QAAQ,GAAG,IAAI,wBAAwB,CAAC,MAAM,CAAC,CAAC;IAEtD,OAAO,SAAS,UAAU,CACxB,OAAgB;QAEhB,OAAO;YACL,QAAQ;YACR,OAAO,EAAE,OAAO,IAAI,QAAQ,CAAC,YAAY;SAC1C,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { SpeechProvider, ResolvedModel } from '../../speech-provider.js';
|
|
2
|
+
export interface FalSpeechProviderConfig {
|
|
3
|
+
apiKey?: string;
|
|
4
|
+
baseURL?: string;
|
|
5
|
+
fetch?: typeof globalThis.fetch;
|
|
6
|
+
}
|
|
7
|
+
export declare class FalSpeechProvider implements SpeechProvider<string, string | {
|
|
8
|
+
url: string;
|
|
9
|
+
}> {
|
|
10
|
+
readonly id = "fal-ai";
|
|
11
|
+
readonly defaultModel = "";
|
|
12
|
+
readonly models: readonly [];
|
|
13
|
+
private readonly apiKey;
|
|
14
|
+
private readonly baseURL;
|
|
15
|
+
private readonly fetchFn;
|
|
16
|
+
constructor(config: FalSpeechProviderConfig);
|
|
17
|
+
generate(options: {
|
|
18
|
+
modelId: string;
|
|
19
|
+
text: string;
|
|
20
|
+
voice?: string | {
|
|
21
|
+
url: string;
|
|
22
|
+
};
|
|
23
|
+
providerOptions?: Record<string, unknown>;
|
|
24
|
+
abortSignal?: AbortSignal;
|
|
25
|
+
headers?: Record<string, string>;
|
|
26
|
+
}): Promise<{
|
|
27
|
+
audio: Uint8Array;
|
|
28
|
+
mediaType: string;
|
|
29
|
+
providerMetadata?: Record<string, unknown>;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
|
32
|
+
export declare function createFal(config?: FalSpeechProviderConfig): (modelId?: string) => ResolvedModel<string | {
|
|
33
|
+
url: string;
|
|
34
|
+
}>;
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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uBAA4B,IAGxC,UAAU,MAAM,KAAG,aAAa,CAAC,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,CAM/E"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { resolveApiKey, handleErrorResponse } from '../../provider-utils.js';
|
|
2
|
+
import { ApiError } from '../../errors.js';
|
|
3
|
+
export class FalSpeechProvider {
|
|
4
|
+
id = 'fal-ai';
|
|
5
|
+
defaultModel = '';
|
|
6
|
+
models = [];
|
|
7
|
+
apiKey;
|
|
8
|
+
baseURL;
|
|
9
|
+
fetchFn;
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.apiKey = config.apiKey;
|
|
12
|
+
this.baseURL = config.baseURL ?? 'https://fal.run';
|
|
13
|
+
this.fetchFn = config.fetch ?? globalThis.fetch;
|
|
14
|
+
}
|
|
15
|
+
async generate(options) {
|
|
16
|
+
if (!options.modelId) {
|
|
17
|
+
throw new Error('fal-ai requires a model ID (e.g., "fal-ai/inworld-tts"). No default model is available.');
|
|
18
|
+
}
|
|
19
|
+
const url = `${this.baseURL}/fal-ai/${options.modelId}`;
|
|
20
|
+
const body = {
|
|
21
|
+
...options.providerOptions,
|
|
22
|
+
text: options.text,
|
|
23
|
+
};
|
|
24
|
+
if (options.voice != null) {
|
|
25
|
+
if (typeof options.voice === 'string') {
|
|
26
|
+
body.voice = options.voice;
|
|
27
|
+
}
|
|
28
|
+
else if ('url' in options.voice) {
|
|
29
|
+
body.audio_url = options.voice.url;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const response = await this.fetchFn(url, {
|
|
33
|
+
method: 'POST',
|
|
34
|
+
headers: {
|
|
35
|
+
'Content-Type': 'application/json',
|
|
36
|
+
'Authorization': `Key ${resolveApiKey(this.apiKey, 'FAL_API_KEY', 'fal')}`,
|
|
37
|
+
...options.headers,
|
|
38
|
+
},
|
|
39
|
+
body: JSON.stringify(body),
|
|
40
|
+
signal: options.abortSignal,
|
|
41
|
+
});
|
|
42
|
+
await handleErrorResponse(response, `fal-ai/${options.modelId}`);
|
|
43
|
+
const json = await response.json();
|
|
44
|
+
const audioResponse = await this.fetchFn(json.audio.url, {
|
|
45
|
+
signal: options.abortSignal,
|
|
46
|
+
});
|
|
47
|
+
if (!audioResponse.ok) {
|
|
48
|
+
throw new ApiError(`API error: ${audioResponse.status}`, {
|
|
49
|
+
statusCode: audioResponse.status,
|
|
50
|
+
model: `fal-ai/${options.modelId}`,
|
|
51
|
+
responseBody: await audioResponse.text().catch(() => undefined),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
const arrayBuffer = await audioResponse.arrayBuffer();
|
|
55
|
+
return {
|
|
56
|
+
audio: new Uint8Array(arrayBuffer),
|
|
57
|
+
mediaType: 'audio/mpeg',
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export function createFal(config = {}) {
|
|
62
|
+
const provider = new FalSpeechProvider(config);
|
|
63
|
+
return function fal(modelId) {
|
|
64
|
+
return {
|
|
65
|
+
provider,
|
|
66
|
+
modelId: modelId ?? provider.defaultModel,
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/providers/fal/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC7E,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAQ3C,MAAM,OAAO,iBAAiB;IACnB,EAAE,GAAG,QAAQ,CAAC;IACd,YAAY,GAAG,EAAE,CAAC;IAElB,MAAM,GAAG,EAAW,CAAC;IAEb,MAAM,CAAqB;IAC3B,OAAO,CAAS;IAChB,OAAO,CAA0B;IAElD,YAAY,MAA+B;QACzC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5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E,UAAU,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;QAEjE,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAgC,CAAC;QAEjE,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE;YACvD,MAAM,EAAE,OAAO,CAAC,WAAW;SAC5B,CAAC,CAAC;QAEH,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE,CAAC;YACtB,MAAM,IAAI,QAAQ,CAAC,cAAc,aAAa,CAAC,MAAM,EAAE,EAAE;gBACvD,UAAU,EAAE,aAAa,CAAC,MAAM;gBAChC,KAAK,EAAE,UAAU,OAAO,CAAC,OAAO,EAAE;gBAClC,YAAY,EAAE,MAAM,aAAa,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC;aAChE,CAAC,CAAC;QACL,CAAC;QAED,MAAM,WAAW,GAAG,MAAM,aAAa,CAAC,WAAW,EAAE,CAAC;QAEtD,OAAO;YACL,KAAK,EAAE,IAAI,UAAU,CAAC,WAAW,CAAC;YAClC,SAAS,EAAE,YAAY;SACxB,CAAC;IACJ,CAAC;CACF;AAED,MAAM,UAAU,SAAS,CAAC,SAAkC,EAAE;IAC5D,MAAM,QAAQ,GAAG,IAAI,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAE/C,OAAO,SAAS,GAAG,CAAC,OAAgB;QAClC,OAAO;YACL,QAAQ;YACR,OAAO,EAAE,OAAO,IAAI,QAAQ,CAAC,YAAY;SAC1C,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { SpeechProvider, ResolvedModel } from '../../speech-provider.js';
|
|
2
|
+
export interface FishAudioSpeechProviderConfig {
|
|
3
|
+
apiKey?: string;
|
|
4
|
+
baseURL?: string;
|
|
5
|
+
fetch?: typeof globalThis.fetch;
|
|
6
|
+
}
|
|
7
|
+
export declare class FishAudioSpeechProvider implements SpeechProvider<string, string> {
|
|
8
|
+
readonly id = "fish-audio";
|
|
9
|
+
readonly defaultModel = "s2-pro";
|
|
10
|
+
readonly models: readonly [{
|
|
11
|
+
readonly id: "s2-pro";
|
|
12
|
+
readonly languages: readonly ["en"];
|
|
13
|
+
}];
|
|
14
|
+
private readonly apiKey;
|
|
15
|
+
private readonly baseURL;
|
|
16
|
+
private readonly fetchFn;
|
|
17
|
+
constructor(config: FishAudioSpeechProviderConfig);
|
|
18
|
+
generate(options: {
|
|
19
|
+
modelId: string;
|
|
20
|
+
text: string;
|
|
21
|
+
voice?: string;
|
|
22
|
+
providerOptions?: Record<string, unknown>;
|
|
23
|
+
abortSignal?: AbortSignal;
|
|
24
|
+
headers?: Record<string, string>;
|
|
25
|
+
}): Promise<{
|
|
26
|
+
audio: Uint8Array;
|
|
27
|
+
mediaType: string;
|
|
28
|
+
providerMetadata?: Record<string, unknown>;
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
31
|
+
export declare function createFishAudio(config?: FishAudioSpeechProviderConfig): (modelId?: string) => ResolvedModel<string>;
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/fish-audio/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAG9E,MAAM,WAAW,6BAA6B;IAC5C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC;AAED,qBAAa,uBAAwB,YAAW,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC;IAC5E,QAAQ,CAAC,EAAE,gBAAgB;IAC3B,QAAQ,CAAC,YAAY,YAAY;IAEjC,QAAQ,CAAC,MAAM;;;OAEJ;IAEX,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAC5C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA0B;gBAEtC,MAAM,EAAE,6BAA6B;IAM3C,QAAQ,CAAC,OAAO,EAAE;QACtB,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC1C,WAAW,CAAC,EAAE,WAAW,CAAC;QAC1B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAClC,GAAG,OAAO,CAAC;QACV,KAAK,EAAE,UAAU,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC5C,CAAC;CAkCH;AAED,wBAAgB,eAAe,CAAC,MAAM,GAAE,6BAAkC,IAG9C,UAAU,MAAM,KAAG,aAAa,CAAC,MAAM,CAAC,CAMnE"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { resolveApiKey, handleErrorResponse } from '../../provider-utils.js';
|
|
2
|
+
export class FishAudioSpeechProvider {
|
|
3
|
+
id = 'fish-audio';
|
|
4
|
+
defaultModel = 's2-pro';
|
|
5
|
+
models = [
|
|
6
|
+
{ id: 's2-pro', languages: ['en'] },
|
|
7
|
+
];
|
|
8
|
+
apiKey;
|
|
9
|
+
baseURL;
|
|
10
|
+
fetchFn;
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.apiKey = config.apiKey;
|
|
13
|
+
this.baseURL = config.baseURL ?? 'https://api.fish.audio';
|
|
14
|
+
this.fetchFn = config.fetch ?? globalThis.fetch;
|
|
15
|
+
}
|
|
16
|
+
async generate(options) {
|
|
17
|
+
const url = `${this.baseURL}/v1/tts`;
|
|
18
|
+
const body = {
|
|
19
|
+
...options.providerOptions,
|
|
20
|
+
text: options.text,
|
|
21
|
+
};
|
|
22
|
+
if (options.voice) {
|
|
23
|
+
body.reference_id = options.voice;
|
|
24
|
+
}
|
|
25
|
+
const response = await this.fetchFn(url, {
|
|
26
|
+
method: 'POST',
|
|
27
|
+
headers: {
|
|
28
|
+
'Content-Type': 'application/json',
|
|
29
|
+
'Authorization': `Bearer ${resolveApiKey(this.apiKey, 'FISH_AUDIO_API_KEY', 'Fish Audio')}`,
|
|
30
|
+
'model': options.modelId,
|
|
31
|
+
...options.headers,
|
|
32
|
+
},
|
|
33
|
+
body: JSON.stringify(body),
|
|
34
|
+
signal: options.abortSignal,
|
|
35
|
+
});
|
|
36
|
+
await handleErrorResponse(response, `fish-audio/${options.modelId}`);
|
|
37
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
38
|
+
const mediaType = response.headers.get('content-type') ?? 'audio/mpeg';
|
|
39
|
+
return {
|
|
40
|
+
audio: new Uint8Array(arrayBuffer),
|
|
41
|
+
mediaType,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export function createFishAudio(config = {}) {
|
|
46
|
+
const provider = new FishAudioSpeechProvider(config);
|
|
47
|
+
return function fishAudio(modelId) {
|
|
48
|
+
return {
|
|
49
|
+
provider,
|
|
50
|
+
modelId: modelId ?? provider.defaultModel,
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/providers/fish-audio/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAQ7E,MAAM,OAAO,uBAAuB;IACzB,EAAE,GAAG,YAAY,CAAC;IAClB,YAAY,GAAG,QAAQ,CAAC;IAExB,MAAM,GAA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AW,EAAE,CAAC;QACjD,MAAM,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,YAAY,CAAC;QAEvE,OAAO;YACL,KAAK,EAAE,IAAI,UAAU,CAAC,WAAW,CAAC;YAClC,SAAS;SACV,CAAC;IACJ,CAAC;CACF;AAED,MAAM,UAAU,eAAe,CAAC,SAAwC,EAAE;IACxE,MAAM,QAAQ,GAAG,IAAI,uBAAuB,CAAC,MAAM,CAAC,CAAC;IAErD,OAAO,SAAS,SAAS,CAAC,OAAgB;QACxC,OAAO;YACL,QAAQ;YACR,OAAO,EAAE,OAAO,IAAI,QAAQ,CAAC,YAAY;SAC1C,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { SpeechProvider, ResolvedModel } from '../../speech-provider.js';
|
|
2
|
+
export interface GoogleSpeechProviderConfig {
|
|
3
|
+
apiKey?: string;
|
|
4
|
+
baseURL?: string;
|
|
5
|
+
fetch?: typeof globalThis.fetch;
|
|
6
|
+
}
|
|
7
|
+
export declare class GoogleSpeechProvider implements SpeechProvider<string, string> {
|
|
8
|
+
readonly id = "google";
|
|
9
|
+
readonly defaultModel = "gemini-2.5-flash-preview-tts";
|
|
10
|
+
readonly models: readonly [{
|
|
11
|
+
readonly id: "gemini-2.5-flash-preview-tts";
|
|
12
|
+
readonly languages: readonly ["en"];
|
|
13
|
+
}, {
|
|
14
|
+
readonly id: "gemini-2.5-pro-preview-tts";
|
|
15
|
+
readonly languages: readonly ["en"];
|
|
16
|
+
}];
|
|
17
|
+
private readonly apiKey;
|
|
18
|
+
private readonly baseURL;
|
|
19
|
+
private readonly fetchFn;
|
|
20
|
+
constructor(config: GoogleSpeechProviderConfig);
|
|
21
|
+
generate(options: {
|
|
22
|
+
modelId: string;
|
|
23
|
+
text: string;
|
|
24
|
+
voice?: string;
|
|
25
|
+
providerOptions?: Record<string, unknown>;
|
|
26
|
+
abortSignal?: AbortSignal;
|
|
27
|
+
headers?: Record<string, string>;
|
|
28
|
+
}): Promise<{
|
|
29
|
+
audio: string;
|
|
30
|
+
mediaType: string;
|
|
31
|
+
providerMetadata?: Record<string, unknown>;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
34
|
+
export declare function createGoogle(config?: GoogleSpeechProviderConfig): (modelId?: string) => ResolvedModel<string>;
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/google/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAG9E,MAAM,WAAW,0BAA0B;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC;AAED,qBAAa,oBAAqB,YAAW,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC;IACzE,QAAQ,CAAC,EAAE,YAAY;IACvB,QAAQ,CAAC,YAAY,kCAAkC;IAEvD,QAAQ,CAAC,MAAM;;;;;;OAGJ;IAEX,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAC5C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA0B;gBAEtC,MAAM,EAAE,0BAA0B;IAMxC,QAAQ,CAAC,OAAO,EAAE;QACtB,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC1C,WAAW,CAAC,EAAE,WAAW,CAAC;QAC1B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAClC,GAAG,OAAO,CAAC;QACV,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,EAAE,MAAM,CAAC;QAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC5C,CAAC;CA8DH;AAED,wBAAgB,YAAY,CAAC,MAAM,GAAE,0BAA+B,IAG3C,UAAU,MAAM,KAAG,aAAa,CAAC,MAAM,CAAC,CAMhE"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { resolveApiKey, handleErrorResponse } from '../../provider-utils.js';
|
|
2
|
+
export class GoogleSpeechProvider {
|
|
3
|
+
id = 'google';
|
|
4
|
+
defaultModel = 'gemini-2.5-flash-preview-tts';
|
|
5
|
+
models = [
|
|
6
|
+
{ id: 'gemini-2.5-flash-preview-tts', languages: ['en'] },
|
|
7
|
+
{ id: 'gemini-2.5-pro-preview-tts', languages: ['en'] },
|
|
8
|
+
];
|
|
9
|
+
apiKey;
|
|
10
|
+
baseURL;
|
|
11
|
+
fetchFn;
|
|
12
|
+
constructor(config) {
|
|
13
|
+
this.apiKey = config.apiKey;
|
|
14
|
+
this.baseURL = config.baseURL ?? 'https://generativelanguage.googleapis.com/v1beta';
|
|
15
|
+
this.fetchFn = config.fetch ?? globalThis.fetch;
|
|
16
|
+
}
|
|
17
|
+
async generate(options) {
|
|
18
|
+
const apiKey = resolveApiKey(this.apiKey, 'GOOGLE_API_KEY', 'Google');
|
|
19
|
+
const voiceName = options.voice ?? 'Kore';
|
|
20
|
+
const speechConfig = {
|
|
21
|
+
voice_config: {
|
|
22
|
+
prebuilt_voice_config: {
|
|
23
|
+
voice_name: voiceName,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
const body = {
|
|
28
|
+
contents: [
|
|
29
|
+
{
|
|
30
|
+
role: 'user',
|
|
31
|
+
parts: [{ text: options.text }],
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
generationConfig: {
|
|
35
|
+
responseModalities: ['audio'],
|
|
36
|
+
speech_config: speechConfig,
|
|
37
|
+
...options.providerOptions,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
const url = `${this.baseURL}/models/${options.modelId}:generateContent?key=${apiKey}`;
|
|
41
|
+
const response = await this.fetchFn(url, {
|
|
42
|
+
method: 'POST',
|
|
43
|
+
headers: {
|
|
44
|
+
'Content-Type': 'application/json',
|
|
45
|
+
...options.headers,
|
|
46
|
+
},
|
|
47
|
+
body: JSON.stringify(body),
|
|
48
|
+
signal: options.abortSignal,
|
|
49
|
+
});
|
|
50
|
+
await handleErrorResponse(response, `google/${options.modelId}`);
|
|
51
|
+
const json = await response.json();
|
|
52
|
+
const part = json.candidates?.[0]?.content?.parts?.find((p) => p.inlineData != null);
|
|
53
|
+
if (!part?.inlineData) {
|
|
54
|
+
throw new Error('No audio data in Gemini TTS response');
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
audio: part.inlineData.data,
|
|
58
|
+
mediaType: part.inlineData.mimeType ?? 'audio/mp3',
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export function createGoogle(config = {}) {
|
|
63
|
+
const provider = new GoogleSpeechProvider(config);
|
|
64
|
+
return function google(modelId) {
|
|
65
|
+
return {
|
|
66
|
+
provider,
|
|
67
|
+
modelId: modelId ?? provider.defaultModel,
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/providers/google/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAQ7E,MAAM,OAAO,oBAAoB;IACtB,EAAE,GAAG,QAAQ,CAAC;IACd,YAAY,GAAG,8BAA8B,CAAC;IAE9C,MAAM,GAAG;QAChB,EAAE,EAAE,EAAE,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