Skip to content

Commit 5afa03e

Browse files
committed
examples : setup audio session viewDidload
This commit adds the setup of the audio session in the viewDidload method of the ViewController.m file. This is necessary to allow the app to record audio. The motivation for this is that without this it was not possible to caputue audio from the microphone. It was possible to click on the Capture button but nothing happened after that, and the button was not marked red indicating that the button could be clicked again to stop capturing. With this change it is possible to capture audio from the microphone and get it transcribed.
1 parent 23af7d5 commit 5afa03e

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

examples/whisper.objc/whisper.objc/ViewController.m

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//
77

88
#import "ViewController.h"
9-
109
#import <whisper/whisper.h>
1110

1211

@@ -84,6 +83,19 @@ - (void)viewDidLoad {
8483
stateInp.n_samples = 0;
8584
stateInp.audioBufferI16 = malloc(MAX_AUDIO_SEC*SAMPLE_RATE*sizeof(int16_t));
8685
stateInp.audioBufferF32 = malloc(MAX_AUDIO_SEC*SAMPLE_RATE*sizeof(float));
86+
// Set up audio session
87+
NSError *error = nil;
88+
89+
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryRecord error:&error];
90+
if (error) {
91+
NSLog(@"Error setting audio session category: %@", error);
92+
}
93+
94+
[[AVAudioSession sharedInstance] setActive:YES error:&error];
95+
if (error) {
96+
NSLog(@"Error activating audio session: %@", error);
97+
}
98+
8799
}
88100

89101
stateInp.isTranscribing = false;

0 commit comments

Comments
 (0)