diff --git a/sdk/typescript/eslint.config.ts b/sdk/typescript/eslint.config.ts index 8b6dda3..86f1d87 100644 --- a/sdk/typescript/eslint.config.ts +++ b/sdk/typescript/eslint.config.ts @@ -18,6 +18,7 @@ export default antfu({ typescript: { tsconfigPath: './tsconfig.json' } }) rules: { '@masknet/no-default-error': 'off', '@masknet/no-then': 'off', + '@masknet/unicode-specific-set': 'off', 'sonarjs/todo-tag': 'warn', }, }) diff --git a/sdk/typescript/src/backend/alibabacloud.ts b/sdk/typescript/src/backend/alibabacloud.ts index 34e516d..1b3fcc2 100644 --- a/sdk/typescript/src/backend/alibabacloud.ts +++ b/sdk/typescript/src/backend/alibabacloud.ts @@ -6,6 +6,16 @@ import { objCamelToSnake } from '@xsai/shared' import type { UnSpeechOptions, VoiceProviderWithExtraOptions } from '../types' export interface UnAlibabaCloudOptions { + /** + * Speech pitch. Range: 0.5 to 2.0. + * @default 1.0 + */ + pitch?: number + /** + * Speech rate. Range: 0.5 to 2.0. + * @default 1.0 + */ + rate?: number /** * Sampling rate of the synthesized audio. * @default 22050 @@ -16,16 +26,6 @@ export interface UnAlibabaCloudOptions { * @default 50 */ volume?: number - /** - * Speech rate. Range: 0.5 to 2.0. - * @default 1.0 - */ - rate?: number - /** - * Speech pitch. Range: 0.5 to 2.0. - * @default 1.0 - */ - pitch?: number } /** @@ -42,13 +42,13 @@ export interface UnAlibabaCloudOptions { */ export const createUnAlibabaCloud = (apiKey: string, baseURL = 'http://localhost:5933/v1/') => { const toUnSpeechOptions = (options: UnAlibabaCloudOptions): UnSpeechOptions => { - const { sampleRate, volume, rate, pitch } = options + const { pitch, rate, sampleRate, volume } = options const extraBody: Record = { + pitch, + rate, sampleRate, volume, - rate, - pitch, } // Remove undefined values before converting keys diff --git a/sdk/typescript/src/backend/elevenlabs.ts b/sdk/typescript/src/backend/elevenlabs.ts index f8730af..f2f4142 100644 --- a/sdk/typescript/src/backend/elevenlabs.ts +++ b/sdk/typescript/src/backend/elevenlabs.ts @@ -171,7 +171,7 @@ export const createUnElevenLabs = (apiKey: string, baseURL = 'http://localhost:5 } return { - query: `provider=elevenlabs`, + query: 'provider=elevenlabs', ...(options ? toUnSpeechOptions(options) : {}), apiKey, baseURL, diff --git a/sdk/typescript/src/backend/index.ts b/sdk/typescript/src/backend/index.ts index 543500d..a1944a6 100644 --- a/sdk/typescript/src/backend/index.ts +++ b/sdk/typescript/src/backend/index.ts @@ -1,32 +1,32 @@ import { createSpeechProviderWithExtraOptions, merge } from '@xsai-ext/shared-providers' -import { MicrosoftRegions } from './microsoft' -import { UnSpeechOptions, VoiceProviderWithExtraOptions } from '../types' +import type { UnSpeechOptions, VoiceProviderWithExtraOptions } from '../types' +import type { MicrosoftRegions } from './microsoft' +export * from './alibabacloud' export * from './elevenlabs' export * from './microsoft' export * from './volcengine' -export * from './alibabacloud' /** @see {@link https://github.com/moeru-ai/unspeech} */ export const createUnSpeech = (apiKey: string, baseURL = 'http://localhost:5933/v1/') => { const voiceProvider: VoiceProviderWithExtraOptions< { - backend: - | 'elevenlabs' - | 'koemotion' - | 'openai' - | 'alibaba' | 'aliyun' | 'ali' | 'bailian' | 'alibaba-model-studio' -} | { - backend: 'microsoft' | 'azure' - region: MicrosoftRegions | string -} | { - backend: 'volcengine' - appId: string -} | { - backend: 'volcano' - appId: string -} + appId: string + backend: 'volcano' + } | { + appId: string + backend: 'volcengine' + } | { + backend: 'azure' | 'microsoft' + region: MicrosoftRegions | string + } | { + backend: + | 'ali' + | 'alibaba' + | 'alibaba-model-studio' + | 'aliyun' | 'bailian' | 'elevenlabs' | 'koemotion' | 'openai' + } > = { voice: (options) => { if (baseURL.endsWith('v1/')) { @@ -38,31 +38,31 @@ export const createUnSpeech = (apiKey: string, baseURL = 'http://localhost:5933/ if (options?.backend === 'microsoft' || options?.backend === 'azure') { return { - query: `region=${options.region}&provider=${options.backend}`, - baseURL, apiKey, + baseURL, + query: `region=${options.region}&provider=${options.backend}`, } } return { - query: `provider=${options?.backend}`, - baseURL, apiKey, + baseURL, + query: `provider=${options?.backend}`, } }, } return merge( - createSpeechProviderWithExtraOptions< - | `elevenlabs/${string}` - | `koemotion/${string}` - | `openai/${string}` - | `volcengine/${string}` - | `volcano/${string}` - | `aliyun/${string}` - | `alibaba/${string}`, + createSpeechProviderWithExtraOptions< + | `alibaba/${string}` + | `aliyun/${string}` + | `elevenlabs/${string}` + | `koemotion/${string}` + | `openai/${string}` + | `volcano/${string}` + | `volcengine/${string}`, UnSpeechOptions >({ apiKey, baseURL }), - voiceProvider + voiceProvider, ) } diff --git a/sdk/typescript/src/backend/volcengine.ts b/sdk/typescript/src/backend/volcengine.ts index 990c008..efcf96c 100644 --- a/sdk/typescript/src/backend/volcengine.ts +++ b/sdk/typescript/src/backend/volcengine.ts @@ -8,14 +8,18 @@ import type { UnSpeechOptions, VoiceProviderWithExtraOptions } from '../types' export interface UnVolcengineOptions { app?: { appId?: string - cluster?: string | 'volcano_tts' - } - user?: { - uid?: string + cluster?: 'volcano_tts' | string } audio?: { - emotion?: string | 'angry' - enableEmotion?: boolean + /** + * @default 160 + */ + bitRate?: 160 | number + /** + * Languages that contextual to the model + */ + contextLanguage?: 'es' | 'id' | 'pt' | string + emotion?: 'angry' | string /** * After calling emotion to set the emotion parameter you can use emotion_scale to * further set the emotion value, the range is 1~5, the default value is 4 when not @@ -31,24 +35,11 @@ export interface UnVolcengineOptions { * @default 4 */ emotionScale?: number + enableEmotion?: boolean /** * @default 'mp3' */ - encoding?: 'wav' | 'pcm' | 'ogg_opus' | 'mp3' - /** - * 0.8~2 - * - * @default 1 - */ - speedRatio?: number - /** - * @default 24000 - */ - rate?: number | 24000 | 8000 | 16000 - /** - * @default 160 - */ - bitRate?: number | 160 + encoding?: 'mp3' | 'ogg_opus' | 'pcm' | 'wav' /** * - undefined: General mixed bilingual * - crosslingual: mix with zh/en/ja/es-ms/id/pt-br @@ -61,34 +52,43 @@ export interface UnVolcengineOptions { * * @default 'en' */ - explicitLanguage?: string | 'crosslingual' | 'zh' | 'en' | 'jp' | 'es-mx' | 'id' | 'pt-br' - /** - * Languages that contextual to the model - */ - contextLanguage?: string | 'id' | 'es' | 'pt' + explicitLanguage?: 'crosslingual' | 'en' | 'es-mx' | 'id' | 'jp' | 'pt-br' | 'zh' | string /** * 0.5 ~ 2 * * @default 1 */ loudnessRatio?: number + /** + * @default 24000 + */ + rate?: 8000 | 16000 | 24000 | number + /** + * 0.8~2 + * + * @default 1 + */ + speedRatio?: number } request?: { + cacheConfig?: Record + disableMarkdownFilter?: boolean + enableLatexTone?: boolean + extraParam?: string reqid?: string - /** - * - set to `ssml` to use SSML - */ - textType?: string | 'ssml' /** * 0 ~ 30000ms */ silenceDuration?: number - withTimestamp?: string - extraParam?: string - disableMarkdownFilter?: boolean - enableLatexTone?: boolean - cacheConfig?: Record + /** + * - set to `ssml` to use SSML + */ + textType?: 'ssml' | string useCache?: boolean + withTimestamp?: string + } + user?: { + uid?: string } } @@ -101,7 +101,6 @@ export interface UnVolcengineOptions { * as ElevenLabs, Azure TTS, Google TTS, etc. * * @param apiKey - Volcano Engine Speech Service Token - * @param appId - Volcano Engine Speech Service App ID * @param baseURL - UnSpeech Instance URL * @returns SpeechProviderWithExtraOptions */ @@ -156,7 +155,7 @@ export const createUnVolcengine = (apiKey: string, baseURL = 'http://localhost:5 } return { - query: `provider=volcengine`, + query: 'provider=volcengine', ...(options ? toUnSpeechOptions(options) : {}), apiKey, baseURL,