检测输入音频的级别?

时间:2015-11-04 14:31:24

标签: ios objective-c iphone audio-recording microphone

我有一个应用程序需要使用麦克风录制用户语音。我试图制作speech to text

我与SpeechKit.framework合作,以下是我使用的代码:

-(void)starRecording{

  self.voiceSearch = [[SKRecognizer alloc] initWithType:SKSearchRecognizerType
                                           detection:SKShortEndOfSpeechDetection
                                           language:[[USER_DEFAULT valueForKey:LANGUAGE_SPEECH_DIC] valueForKey:@"record"]
                                           delegate:self];
}

- (void)recognizer:(SKRecognizer *)recognizer didFinishWithResults:(SKRecognition *)results {
        long numOfResults = [results.results count];

        if (numOfResults > 0) {
            // update the text of text field with best result from SpeechKit
            self.recordString = [results firstResult];
            [self sendChatWithMediaType:@"messageCall" MediaUrl:@"" ContactDetail:@"{}" LocationDetail:@"{}"];

            [self.voiceSearch stopRecording];
        }


        if (self.voiceSearch) {
            [self.voiceSearch cancel];
        }
        [self starRecording];
    }

这使得SKRecognizer始终处于打开状态,这会降低应用程序的性能。

我想在麦克风检测输入音频时启动SKRecognizer

我有一个方法吗?当麦克风为我输入声音时调用的方法或总是返回检测到的音频电平的方法?

谢谢!

1 个答案:

答案 0 :(得分:0)

您需要使用SpeechKit类来设置音频。 在这里查看详细信息;

http://www.raywenderlich.com/60870/building-ios-app-like-siri

该项目展示了如何检测音频阈值;

github.com/picciano/iOS-Audio-Recoginzer