Last active
October 22, 2018 13:54
-
-
Save kshala-ford/dde53da62be70e082c1b37ede6177683 to your computer and use it in GitHub Desktop.
Use the audio IO manager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// how to create an audio IO manager. You should do this right after the SDL manager is created | |
self.audioManager = [[SDLAudioIOManager alloc] initWithManager:self.sdlManager delegate:self]; | |
self.audioManager.inputStreamPrompt = [[SDLTTSChunk alloc] initWithText:SDLPrerecordedSpeechListen type:SDLSpeechCapabilitiesPrerecorded]; | |
self.audioManager.inputStreamText = @"Listening..."; | |
// how to start the audio IO manager. Whenever the user presses the mic button on the screen | |
[self.audioManager startInputStream]; // this is it | |
// how to stop the audio IO manager if you have recognized user input | |
[self.audioManager stopInputStream]; | |
// output stream related (custom speech, voice instructions) | |
- (void)audioManagerDidStartOutputStream:(SDLAudioIOManager *)audioManager { | |
NSLog(@"%s", __FUNCTION__); | |
} | |
- (void)audioManagerDidStopOutputStream:(SDLAudioIOManager *)audioManager { | |
NSLog(@"%s", __FUNCTION__); | |
} | |
- (void)audioManager:(SDLAudioIOManager *)audioManager didFinishPlayingURL:(NSURL *)url { | |
NSLog(@"%s", __FUNCTION__); | |
} | |
- (void)audioManager:(SDLAudioIOManager *)audioManager errorDidOccurForURL:(NSURL *)url error:(NSError *)error { | |
NSLog(@"%s", __FUNCTION__); | |
} | |
// input stream related (driver speaking) | |
- (void)audioManager:(SDLAudioIOManager *)audioManager didStartInputStreamWithOptions:(SDLAudioPassThruCapabilities *)options { | |
NSLog(@"%s", __FUNCTION__); | |
[self.audioRecorder startAudioRecordingToFileAtPath:self.audioFile amplifierMode:SDLAudioRecorderAmplifierModeLiveProcessing capabilities:options]; | |
} | |
- (void)audioManager:(SDLAudioIOManager *)audioManager didReceiveAudioData:(NSData *)audioData { | |
NSLog(@"%s", __FUNCTION__); | |
[self.audioRecorder writeAudioData:audioData]; | |
} | |
- (void)audioManager:(SDLAudioIOManager *)audioManager didFinishInputStreamWithResult:(SDLResult)result { | |
NSLog(@"%s", __FUNCTION__); | |
if ([result isEqualToEnum:SDLResultSuccess]) { | |
[self.audioRecorder finishAudioRecording]; | |
[self playAudio]; // just an example what to do with the audio | |
} else { | |
[self.audioRecorder cancelAudioRecording]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment