#import "HiBaiduTts.h"
#import "HiSpeechSynthesizer.h"

@interface HiBaiduTts ()

@property(nonatomic,strong)HiSpeechSynthesizer *speechSynthesizer;

@end

@implementation HiBaiduTts

RCT_EXPORT_MODULE()

// Example method
// See // https://reactnative.dev/docs/native-modules-ios
RCT_EXPORT_METHOD(initSDK:(NSString *)apiKey secretKey:(NSString *)secretKey)
{
    if(!_speechSynthesizer){
        _speechSynthesizer = [[HiSpeechSynthesizer alloc] initApiKey:apiKey secretKey:secretKey];
    }
}

RCT_EXPORT_METHOD(speak:(NSString *)text)
{
    if(_speechSynthesizer){
        [_speechSynthesizer synthesizeText:text];
    }
}

RCT_EXPORT_METHOD(setSpeaker:(NSString *)speaker)
{
    if(_speechSynthesizer){
        [_speechSynthesizer setSpeaker:speaker];
    }
}

RCT_EXPORT_METHOD(setVolume:(NSNumber *)value)
{
    if(_speechSynthesizer){
        [_speechSynthesizer setVolume:value];
    }
}

RCT_EXPORT_METHOD(setSpeed:(NSNumber *)value)
{
    if(_speechSynthesizer){
        [_speechSynthesizer setSpeed:value];
    }
}

RCT_EXPORT_METHOD(setPitch:(NSNumber *)value)
{
    if(_speechSynthesizer){
        [_speechSynthesizer setPitch:value];
    }
}

RCT_EXPORT_METHOD(setAudioSessionCategory:(NSNumber *)category)
{
    if(_speechSynthesizer){
        [_speechSynthesizer setAudioSessionCategory:category];
    }
}

RCT_EXPORT_METHOD(setAudioSessionEnable:(NSNumber *)value)
{
    if(_speechSynthesizer){
        [_speechSynthesizer setAudioSessionEnable:value];
    }
}



RCT_EXPORT_METHOD(cancel)
{
    if(_speechSynthesizer){
        [_speechSynthesizer cancel];
    }
}


- (dispatch_queue_t)methodQueue
{
  return dispatch_get_main_queue();
}

@end
