Short Text to Speech
IOS SDK
TTS IOS SDK
1. Integration Steps
-
Manual Import: Drag the
HYTTS.frameworkinto your project. Then, inGeneral -> Frameworks, Libraries, and Embedded Content, change theEmbedsetting ofHYTTS.frameworktoEmbed & Sign. -
Ensure that the following pods are included: SocketRocket0.6.0、 AFNetworking, SSZipArchive 2.4.3。
2. Add Application-Related Permissions
1.Add Privacy - Microphone Usage Description to your project's info.plist file to enable microphone access.
3. Call Steps/Example Code
3.1 Get Instance
- Obtain an instance of
TTS
TTSParams *params = [[TTSParams alloc] init];
params.langType = @"";
[[TTSManger shareInstance] setSdkParams:params]
[[TTSManger shareInstance] initWithWithAppid:@"" WithAppSecret:@"" WithinitBlock:^(NSError * _Nonnull Error) {
if (Error == nil) {
NSLog(@"Initialization successful");
}
}];
3.2 Authorization Activation
(1)Configure Authorization Parameters
| Name | Type | Description | Default Value |
|---|---|---|---|
| online | string | true for online, false for offline | true |
TTSParams *parames = [[TTSManger getTTSManger] getSdkParams];
params.online = @"true";//Online or offline3.3 Parameter Settings
| Parameter | Type | Required | Description | Default Value |
|---|---|---|---|---|
| text | String | Yes | Text to be synthesized, length limit: 1024 bytes (UTF-8 encoding) | Required |
| lang_type | String | Yes | Language option | Required |
| voice | String | No | VoiceID | Japanese: Yuko English:Julie Chinese:Xiaohui |
| format | String | No | Audio encode format, wav / pcm / mp3, note: wav does not support streaming | pcm |
| sample_rate | Integer | No | Audio sample rate, options are 8000, 16000, 24000 | 24000 |
| volume | Integer | No | Volume, parameter range [0.1, 3], usually retaining one decimal place is sufficient | 1.0 |
| speech_rate | Float | No | Speech rate, parameter range [0.2, 3], usually retaining one decimal place is sufficient | 1.0 |
| pitch_rate | Float | No | Pitch rate, parameter range [0.1, 3], usually retaining one decimal place is sufficient | 1.0 |
| emotion | String | No | Emotional style | No |
| silence_duration | Integer | No | Silence duration at the end of the sentence, in ms | 125 |
| enable_timestamp | Boolean | No | Timestamp related, when passed as true, it indicates enabling, and the original text’s timestamps can be returned. Note: multiple consecutive punctuation or spaces in the original text will still be processed, but this will not affect the continuity of the timestamps | false |
TTSParams *params = [[TTSParams alloc] init]; params.text = @"";
params.langType = @"";
params.format = @"pcm";
params.voice = @"xiaohui";
params.volume = 50;
params.speech_rate = 1;
params.pitch_rate = 0;
params.sample_rate = 16000;
[[TTSManger shareInstance] setSdkParams:params];3.4 Start/Stop Synthesis
TTSParams *parames = [[TTSManger getTTSManger] getSdkParams];
parames.text = @"";
[[TTSManger getTTSManger] onStart];//Start synthesis
[[TTSManger getTTSManger] onStop]; //Stop synthesis