Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase the audio input level #381

Open
desmeit opened this issue Nov 20, 2019 · 1 comment
Open

Increase the audio input level #381

desmeit opened this issue Nov 20, 2019 · 1 comment

Comments

@desmeit
Copy link

desmeit commented Nov 20, 2019

- (void) configureAudioSession
{

    AVAudioSession* session = [AVAudioSession
                               sharedInstance];

    // Don't activate the audio session yet
    [session setActive:NO error:NULL];

    // Play music even in background and dont stop playing music
    // even another app starts playing sound
    [session setCategory:AVAudioSessionCategoryRecord error:NULL];
    
    double sampleRate = 16000.0;
    [session setPreferredSampleRate:sampleRate error:NULL];

    // Active the audio session
    [session setActive:YES error:NULL];
}

- (void) initMic {
    [self configureAudioSession];
    AudioStreamBasicDescription audioStreamBasicDescription = [EZAudioUtilities monoFloatFormatWithSampleRate:16000];
    audioStreamBasicDescription.mFormatID = kAudioFormatLinearPCM;
    audioStreamBasicDescription.mSampleRate = 16000.0;
    audioStreamBasicDescription.mFramesPerPacket = 1;
    audioStreamBasicDescription.mBytesPerPacket = 2;
    audioStreamBasicDescription.mBytesPerFrame = 2;
    audioStreamBasicDescription.mChannelsPerFrame = 1;
    audioStreamBasicDescription.mBitsPerChannel = 16;
    audioStreamBasicDescription.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked;
    audioStreamBasicDescription.mReserved = 0;

    NSArray *inputs = [EZAudioDevice inputDevices];
    [self.microphone setDevice:[inputs lastObject]];
    self.microphone = [EZMicrophone microphoneWithDelegate:self withAudioStreamBasicDescription:audioStreamBasicDescription];
    [self.microphone startFetchingAudio];
}

-(void) microphone:(EZMicrophone *)microphone
  hasAudioReceived:(float **)buffer
    withBufferSize:(UInt32)bufferSize
withNumberOfChannels:(UInt32)numberOfChannels {
    dispatch_async(dispatch_get_main_queue(),^{
        int result = _snowboyDetect->RunDetection(buffer[0], bufferSize);
        if (result >= 1) {
             NSLog(@"Hotword Detected");
            NSString *modelName = modelsList[result - 1];
            NSDictionary *jsonObj = @{@"message":@"Hotword Detected",@"modelname": modelName};
            [self triggerJSEventData:jsonObj];
           // [self triggerJSEvent:@"Hotword Detected"];
            detection_countdown = 30;
        } else {
            if (detection_countdown == 0){
                NSLog(@"No Hotword Detected");
                [self triggerJSEvent:@"No Hotword Detected"];
            } else {
                detection_countdown--;
            }
        }
    });
}

I use EZAudio which is working with Snowboy Hotword Detection.
On Android the Hotword ist recognizing perfectly, even if I speak quiet. With ios the Hotword is not recognized if I speak very quietly. Now my question: Is it possible to increase the microphone level on IOS? I have a feeling it's related to that. Is there any way to increase the mic input level?

@desmeit desmeit changed the title Increase the audio level Increase the audio input level Nov 20, 2019
@designerfuzzi
Copy link

As of 2019 you need to allow Microphone Access with proper entry in info.plist and initiating a dialog to ask the user.
Once the consent is given by the user, the microphone or any audio input signal should be available.
Until then, without consent, no audio can be recorded or nothing will arrive at EZMicrophone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants