Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support setting utterance volume on iOS. #133

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ class Tts extends NativeEventEmitter {
// compatibility with old-style voiceId argument passing
if (typeof options === 'string') {
if (Platform.OS === 'ios') {
return TextToSpeech.speak(utterance, options);
return TextToSpeech.speak(utterance, { iosVoiceId: options } );
} else {
return TextToSpeech.speak(utterance, {});
}
} else {
if (Platform.OS === 'ios') {
return TextToSpeech.speak(utterance, options.iosVoiceId);
return TextToSpeech.speak(utterance, options);
} else {
return TextToSpeech.speak(utterance, options.androidParams || {});
}
Expand Down
11 changes: 9 additions & 2 deletions ios/TextToSpeech/TextToSpeech.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ + (BOOL)requiresMainQueueSetup
}

RCT_EXPORT_METHOD(speak:(NSString *)text
voice:(NSString *)voice
params:(NSDictionary *)params
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)
reject:(RCTPromiseRejectBlock)reject
)
{
if(!text) {
reject(@"no_text", @"No text to speak", nil);
Expand All @@ -55,6 +56,7 @@ + (BOOL)requiresMainQueueSetup

AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:text];

NSString* voice = [params valueForKey:@"iosVoiceId"];
if(voice) {
utterance.voice = [AVSpeechSynthesisVoice voiceWithIdentifier:voice];
} else if (_defaultVoice) {
Expand All @@ -69,6 +71,11 @@ + (BOOL)requiresMainQueueSetup
utterance.pitchMultiplier = _defaultPitch;
}

NSNumber* volume = [params valueForKey:@"volume"];
if(volume) {
utterance.volume = [volume floatValue];
}

if([_ignoreSilentSwitch isEqualToString:@"ignore"]) {
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
} else if([_ignoreSilentSwitch isEqualToString:@"obey"]) {
Expand Down