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

Added volume to iOS #205

Open
wants to merge 2 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
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ Additionally, speak() allows to pass platform-specific options.
// IOS
Tts.speak('Hello, world!', {
iosVoiceId: 'com.apple.ttsbundle.Moira-compact',
rate: 0.5,
rate: 0.5,
volume: 1.0
});
// Android
Tts.speak('Hello, world!', {
Expand All @@ -79,6 +80,7 @@ The supported options for IOS are:

- `iosVoiceId` which voice to use, check [voices()](#list-voices) for available values
- `rate` which speech rate this line should be spoken with. Will override [default rate](#set-default-speech-rate) if set for this utterance.
- `volume` sets the volume for the speech.

Stop speaking and flush the TTS queue.

Expand Down Expand Up @@ -151,6 +153,16 @@ Sets default voice, pass one of the voiceId as reported by a call to Tts.voices(
Tts.setDefaultVoice('com.apple.ttsbundle.Moira-compact');
```

### Set default Volume

*(only for iOS)*

Sets default volume for the speech. This should be between 0.0 and 1.0

```js
Tts.setDefaultVolume(0.8);
```

### Set default Speech Rate

Sets default speech rate. The rate parameter is a float where where 0.01 is a slowest rate and 0.99 is the fastest rate.
Expand Down
5 changes: 4 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export type TtsError = {
| "Android AudioManager error"
| "not_available"
| "not_found"
| "bad_rate";
| "bad_rate"
| "bad_volume";
message: string;
};

Expand Down Expand Up @@ -82,6 +83,7 @@ export type Options =
| {
iosVoiceId: string;
rate: number;
volume: number;
androidParams: AndroidOptions;
};

Expand All @@ -93,6 +95,7 @@ export class ReactNativeTts extends RN.NativeEventEmitter {
setDefaultEngine: (engineName: string) => Promise<boolean>;
setDefaultVoice: (voiceId: string) => Promise<"success">;
setDefaultRate: (rate: number, skipTransform?: boolean) => Promise<"success">;
setDefaultVolume: (volume: number) => Promise<"success">;
setDefaultPitch: (pitch: number) => Promise<"success">;
setDefaultLanguage: (language: string) => Promise<"success">;
setIgnoreSilentSwitch: (ignoreSilentSwitch: IOSSilentSwitchBehavior) => Promise<boolean>;
Expand Down
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ class Tts extends NativeEventEmitter {
setDefaultRate(rate, skipTransform) {
return TextToSpeech.setDefaultRate(rate, !!skipTransform);
}
setDefaultVolume(volume) {
if (Platform.OS === 'ios') {
return TextToSpeech.setDefaultVolume(volume);
}
else {
return Promise.resolve()
}
}

setDefaultPitch(pitch) {
return TextToSpeech.setDefaultPitch(pitch);
Expand Down
26 changes: 26 additions & 0 deletions ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Uncomment the next line to define a global platform for your project
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
require_relative '../node_modules/react-native/scripts/react_native_pods'
platform :ios, '11.0'

# ignore all warnings from all pods
inhibit_all_warnings!

target 'TextToSpeech' do

config = use_native_modules!

use_react_native!(:path => config["reactNativePath"])


# Enables Flipper.
#
# Note that if you have use_frameworks! enabled, Flipper will not work and
# you should disable these next few lines.

#use_flipper!
#post_install do |installer|
# flipper_post_install(installer)
#end

end
Loading