narraleaf-react
Version:
A React visual novel player framework
90 lines (89 loc) • 2.46 kB
TypeScript
import { Actionable } from "../action/actionable";
import { LogicAction } from "../game";
import { Chained, Proxied } from "../action/chain";
type ChainedSound = Proxied<Sound, Chained<LogicAction.Actions>>;
export declare enum SoundType {
Voice = "voice",
Bgm = "bgm",
Sound = "sound"
}
export type VoiceIdMap = Record<string | number, string | Sound>;
export type VoiceSrcGenerator = (id: string | number) => string | Sound;
export interface ISoundUserConfig {
/**
* Sound source should be a URL or a base64 string
*/
src: string;
/**
* Whether to loop, if sync and loop are both true, sync will be treated as **false**
* @default false
*/
loop: boolean;
/**
* Initial volume, between 0 and 1
* @default 1
*/
volume: number;
/**
* Playback rate, 0.5 to 4
* @default 1
*/
rate: number;
/**
* Set to `true` to force HTML5 Audio.
* This should be used for large audio files
* so that you don't have to wait for the full file to be downloaded and decoded before playing.
* @default false
*/
streaming: boolean;
/**
* Initial position in seconds
* @default 0
*/
seek: number;
/**
* The type of the sound
* @default SoundType.Sound
*/
type: SoundType;
}
export declare class Sound extends Actionable<SoundDataRaw, Sound> {
static voice(arg0: Partial<ISoundUserConfig> | string): Sound;
static bgm(arg0: Partial<ISoundUserConfig> | string): Sound;
static sound(arg0: Partial<ISoundUserConfig> | string): Sound;
constructor(config?: Partial<ISoundUserConfig>);
constructor(src?: string);
constructor(arg0: Partial<ISoundUserConfig> | string);
/**
* Start playing the sound and **wait for it to finish**
*
* This action will be resolved when the sound reaches the end
* @chainable
*/
play(duration?: number): ChainedSound;
/**
* @chainable
*/
stop(duration?: number): ChainedSound;
/**
* @chainable
*/
setVolume(volume: number, duration?: number): ChainedSound;
/**
* @chainable
*/
setRate(rate: number): ChainedSound;
/**
* @chainable
*/
pause(duration?: number): ChainedSound;
/**
* @chainable
*/
resume(duration?: number): ChainedSound;
/**
* Create a sound with the same configuration
*/
copy(): Sound;
}
export {};