Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/typescript/eslint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
})
Expand Down
26 changes: 13 additions & 13 deletions sdk/typescript/src/backend/alibabacloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

/**
Expand All @@ -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<string, unknown> = {
pitch,
rate,
sampleRate,
volume,
rate,
pitch,
}

// Remove undefined values before converting keys
Expand Down
2 changes: 1 addition & 1 deletion sdk/typescript/src/backend/elevenlabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
62 changes: 31 additions & 31 deletions sdk/typescript/src/backend/index.ts
Original file line number Diff line number Diff line change
@@ -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/')) {
Expand All @@ -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,
)
}
73 changes: 36 additions & 37 deletions sdk/typescript/src/backend/volcengine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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<string, unknown>
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<string, unknown>
/**
* - set to `ssml` to use SSML
*/
textType?: 'ssml' | string
useCache?: boolean
withTimestamp?: string
}
user?: {
uid?: string
}
}

Expand All @@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since appId is no longer a direct parameter, this is a breaking change for the createUnVolcengine function. To help users adapt, I suggest updating the JSDoc to explain how to provide the appId now.

For example, you could add a note to the function's description:

/**
 * ...
 *
 * Note: The `appId` for Volcano Engine must be provided in the `options` object for each API call, under `app.appId`.
 *
 * @param apiKey - Volcano Engine Speech Service Token
 * @param baseURL - UnSpeech Instance URL
 * @returns SpeechProviderWithExtraOptions
 */

This will make the new usage clear to developers.

* @param baseURL - UnSpeech Instance URL
* @returns SpeechProviderWithExtraOptions
*/
Expand Down Expand Up @@ -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,
Expand Down
Loading