@aituber-onair/voice
Version:
Voice synthesis library for AITuber OnAir
132 lines (131 loc) • 4.25 kB
TypeScript
import { Talk } from '../types/voice';
import { VoiceEngine } from './VoiceEngine';
/**
* MiniMax endpoint types
*/
export type MinimaxEndpoint = 'global' | 'china';
/**
* MiniMax voice speaker information
*/
export interface MinimaxVoiceSpeaker {
voice_id: string;
voice_name: string;
gender: string;
language: string;
preview_audio?: string;
}
/**
* MiniMax TTS voice synthesis engine
*/
export declare class MinimaxEngine implements VoiceEngine {
private groupId?;
private model;
private defaultVoiceId;
private language;
private endpoint;
/**
* Set GroupId for MiniMax API
*
* GroupId is a unique identifier for the user group in MiniMax's system.
* Unlike other TTS engines that only require an API key, MiniMax requires both
* an API key and a GroupId for authentication and usage tracking.
*
* This GroupId is used by MiniMax for:
* - User group management
* - Usage statistics tracking
* - Billing and quota management
*
* You must obtain this pre-generated value from your MiniMax account dashboard.
*
* @param groupId GroupId for MiniMax API (required for production synthesis)
*/
setGroupId(groupId: string): void;
/**
* Set endpoint region for MiniMax API
* @param endpoint Endpoint region ('global' or 'china')
*/
setEndpoint(endpoint: MinimaxEndpoint): void;
/**
* Set model for MiniMax TTS
* @param model Model name (speech-02-hd, speech-02-turbo, speech-01-hd, speech-01-turbo)
*/
setModel(model: string): void;
/**
* Set language boost
* @param language Language to boost recognition
*/
setLanguage(language: string): void;
/**
* Get current API endpoint URL based on selected endpoint
* @returns API endpoint URL
*/
private getTtsApiUrl;
/**
* Get current voice list API endpoint URL based on selected endpoint
* @returns Voice list API endpoint URL
*/
private getVoiceListApiUrl;
/**
* Get available voice speakers list
* Requires only API key
* @param apiKey MiniMax API key
* @returns Promise<MinimaxVoiceSpeaker[]>
*/
getVoiceList(apiKey: string): Promise<MinimaxVoiceSpeaker[]>;
/**
* Test voice synthesis with minimal requirements
* Requires API key and voice ID, but not GroupId
* @param text Text to synthesize (shorter text recommended for testing)
* @param voiceId Voice ID to test
* @param apiKey MiniMax API key
* @returns Promise<ArrayBuffer>
*/
testVoice(text: string, voiceId: string, apiKey: string): Promise<ArrayBuffer>;
/**
* Full production audio synthesis
* Requires API key, voice ID, and GroupId
* @param input Talk object
* @param speaker Voice ID
* @param apiKey MiniMax API key
* @param voiceActor Not used for MiniMax (for interface compatibility)
* @returns Promise<ArrayBuffer>
*/
fetchAudio(input: Talk, speaker: string, apiKey?: string, voiceActor?: any): Promise<ArrayBuffer>;
/**
* Audio synthesis with flexible GroupId requirement
* @param input Talk object
* @param speaker Voice ID
* @param apiKey MiniMax API key
* @param requireGroupId Whether to require GroupId (default: true)
* @returns Promise<ArrayBuffer>
*/
fetchAudioWithOptions(input: Talk, speaker: string, apiKey?: string, requireGroupId?: boolean): Promise<ArrayBuffer>;
/**
* Check if GroupId is configured
* @returns boolean
*/
hasGroupId(): boolean;
/**
* Get current endpoint setting
* @returns MinimaxEndpoint
*/
getEndpoint(): MinimaxEndpoint;
/**
* Set custom API endpoint URL (VoiceEngine interface compatibility)
* @param apiUrl custom API endpoint URL
*/
setApiEndpoint(apiUrl: string): void;
/**
* Get voice settings based on emotion
* @param emotion Emotion type
* @returns Voice settings
*/
private getVoiceSettings;
/**
* Convert hex string to ArrayBuffer
* @param hex Hex string
* @returns ArrayBuffer
*/
private hexToArrayBuffer;
getTestMessage(textVoiceText?: string): string;
}