Since your user will be driving while interacting with your SDL app, speech phrases can provide important feedback to your user. At any time during your app's lifecycle you can send a speech phrase using the SDLSpeak
request and the head unit's text-to-speech (TTS) engine will produce synthesized speech from your provided text.
When using the SDLSpeak
RPC, you will receive a response from the head unit once the operation has completed. From the response you will be able to tell if the speech was completed, interrupted, rejected or aborted. It is important to keep in mind that a speech request can interrupt another ongoing speech request. If you want to chain speech requests you must wait for the current speech request to finish before sending the next speech request.
On Manticore, spoken feedback works best in Google Chrome, Mozilla Firefox, or Microsoft Edge. Spoken feedback does not work in Apple Safari at this time.
The speech request you send can simply be a text phrase, which will be played back in accordance with the user's current language settings, or it can consist of phoneme specifications to direct SDL’s TTS engine to speak a language-independent, speech-sculpted phrase. It is also possible to play a pre-recorded sound file (such as an MP3) using the speech request. For more information on how to play a sound file please refer to Playing Audio Indications.
Once you have successfully connected to the module, you can access supported speech capabilities properties on the SDLManager.systemCapabilityManager
instance.
NSArray<SDLSpeechCapabilities> *speechCapabilities = self.sdlManager.systemCapabilityManager.speechCapabilities;
let speechCapabilities = sdlManager.systemCapabilityManager.speechCapabilities
Below is a list of commonly supported speech capabilities.
Speech Capability | Description |
---|---|
Text | Text phrases |
SAPI Phonemes | Microsoft speech synthesis API |
File | A pre-recorded sound file |
Once you know what speech capabilities are supported by the module, you can create the speak requests.
SDLSpeak *speak = [[SDLSpeak alloc] initWithTTS:@"hello"];
let speech = SDLSpeak(tts: "hello")
NSArray<SDLTTSChunk *> *sapiPhonemesTTSChunks = [SDLTTSChunk sapiChunksFromString:@"h eh - l ow 1"]; SDLSpeak *speak = [[SDLSpeak alloc] initWithTTSChunks:sapiPhonemesTTSChunks];
let sapiPhonemesTTSChunks = SDLTTSChunk.sapiChunks(from: "h eh - l ow 1") let speech = SDLSpeak(ttsChunks: sapiPhonemesTTSChunks)
[self.sdlManager sendRequest:speak withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { if (!response.success.boolValue) { if ([response.resultCode isEqualToEnum:SDLResultDisallowed]) { <#The app does not have permission to use the speech request#> } else if ([response.resultCode isEqualToEnum:SDLResultRejected]) { <#The request was rejected because a higher priority request is in progress#> } else if ([response.resultCode isEqualToEnum:SDLResultAborted]) { <#The request was aborted by another higher priority request#> } else { <#Some other error occurred#> } return; } <#Speech was successfully spoken#> }];
sdlManager.send(request: speech) { (request, response, error) in guard let response = response as? SDLSpeakResponse else { return } guard response.success.boolValue == true else { switch response.resultCode { case .disallowed: <#The app does not have permission to use the speech request#> case .rejected: <#The request was rejected because a higher priority request is in progress#> case .aborted: <#The request was aborted by another higher priority request#> default: <#Some other error occurred#> } return } <#Speech was successfully spoken#> }