Skip to content
This repository was archived by the owner on Jan 13, 2023. It is now read-only.
Open
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
34 changes: 20 additions & 14 deletions speech/Objective-C/Speech-gRPC-Streaming/Speech/AudioController.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

@interface AudioController () {
AudioComponentInstance remoteIOUnit;
BOOL audioComponentInitialized;
}
@end

Expand Down Expand Up @@ -126,6 +127,7 @@ - (OSStatus) prepareWithSampleRate:(double) specifiedSampleRate {
AVAudioSession *session = [AVAudioSession sharedInstance];

NSError *error;

BOOL ok = [session setCategory:AVAudioSessionCategoryRecord error:&error];
NSLog(@"set category %d", ok);

Expand All @@ -143,20 +145,24 @@ - (OSStatus) prepareWithSampleRate:(double) specifiedSampleRate {
double sampleRate = session.sampleRate;
NSLog (@"hardware sample rate = %f, using specified rate = %f", sampleRate, specifiedSampleRate);
sampleRate = specifiedSampleRate;

// Describe the RemoteIO unit
AudioComponentDescription audioComponentDescription;
audioComponentDescription.componentType = kAudioUnitType_Output;
audioComponentDescription.componentSubType = kAudioUnitSubType_RemoteIO;
audioComponentDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
audioComponentDescription.componentFlags = 0;
audioComponentDescription.componentFlagsMask = 0;

// Get the RemoteIO unit
AudioComponent remoteIOComponent = AudioComponentFindNext(NULL,&audioComponentDescription);
status = AudioComponentInstanceNew(remoteIOComponent,&(self->remoteIOUnit));
if (CheckError(status, "Couldn't get RemoteIO unit instance")) {
return status;
if (!audioComponentInitialized) {

audioComponentInitialized = YES;
// Describe the RemoteIO unit
AudioComponentDescription audioComponentDescription;
audioComponentDescription.componentType = kAudioUnitType_Output;
audioComponentDescription.componentSubType = kAudioUnitSubType_RemoteIO;
audioComponentDescription.componentManufacturer = kAudioUnitManufacturer_Apple;
audioComponentDescription.componentFlags = 0;
audioComponentDescription.componentFlagsMask = 0;

// Get the RemoteIO unit
AudioComponent remoteIOComponent = AudioComponentFindNext(NULL,&audioComponentDescription);
status = AudioComponentInstanceNew(remoteIOComponent,&(self->remoteIOUnit));
if (CheckError(status, "Couldn't get RemoteIO unit instance")) {
return status;
}

}

UInt32 oneFlag = 1;
Expand Down