import { NativeModules, Platform } from 'react-native';
const LINKING_ERROR =
`The package 'react-native-hi-baidu-tts' doesn't seem to be linked. Make sure: \n\n` +
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
'- You rebuilt the app after installing the package\n' +
'- You are not using Expo managed workflow\n';
const HiBaiduTts = NativeModules.HiBaiduTts
? NativeModules.HiBaiduTts
: new Proxy(
{},
{
get() {
throw new Error(LINKING_ERROR);
},
}
);
export enum AudioSessionCategory {
AudioSessionCategoryAmbient,
AudioSessionCategorySoloAmbient,
AudioSessionCategoryPlayback,
AudioSessionCategoryPlayAndRecord,
}
export function initSDK(apiKey: string, secretKey: string, appId: string) {
HiBaiduTts.initSDK(apiKey, secretKey, appId);
}
export function speak(text: string): Promise<string> {
return HiBaiduTts.speak(text);
}
export function setSpeaker(text: string) {
HiBaiduTts.setSpeaker(text);
}
//0~15
export function setVolume(value: number) {
HiBaiduTts.setVolume(value);
}
//0~9
export function setSpeed(value: number) {
HiBaiduTts.setSpeed(value);
}
//0~9
export function setPitch(value: number) {
HiBaiduTts.setPitch(value);
}
//only ios
export function setAudioSessionCategory(category: AudioSessionCategory) {
if (Platform.OS === 'ios') HiBaiduTts.setAudioSessionCategory(category);
}
export function setAudioSessionEnable(enable: boolean) {
if (Platform.OS === 'ios') HiBaiduTts.setAudioSessionEnable(enable);
}
export default {
initSDK,
speak,
setSpeaker,
setVolume,
setSpeed,
setPitch,
setAudioSessionEnable,
setAudioSessionCategory,
};