Newer
Older
react-native-hi-baidu-tts / src / index.tsx
xiaobaoafei on 25 Apr 2022 初始化
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 function initSDK(apiKey: string, secretKey: string) {
  HiBaiduTts.initSDK(apiKey, secretKey);
}

export function speak(text: string) {
  HiBaiduTts.speak(text);
}

export function setSpeaker(text: string) {
  HiBaiduTts.setSpeaker(text);
}

export default {
  initSDK,
  speak,
  setSpeaker,
};