0
我正在嘗試編程一個應用程序,該麥克風使用平均功率來觸發遊戲響應。我正在使用-init
以下代碼:麥克風輸入在模擬器中工作,而不是在手機上xcode
NSURL *url = [NSURL fileURLWithPath:@"/dev/null"];
NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat: 44100.0], AVSampleRateKey, [NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,[NSNumber numberWithInt: AVAudioQualityMax], AVEncoderAudioQualityKey,il];
NSError *error;
recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];
if (recorder) {
[recorder prepareToRecord];
recorder.meteringEnabled = YES;
[recorder record];
levelTimer = [NSTimer scheduledTimerWithTimeInterval: 0.03 target: self selector: @selector(myMethod:) userInfo: nil repeats: YES];
在我的方法 浮soundLevel = [錄音機averagePowerForChannel:0];
觸發在模擬器中正常工作,但不工作時,我把它放在我的手機上進行測試。我究竟做錯了什麼?
此解決方案幫助我使麥克風工作。 http://stackoverflow.com/questions/6350420/how-to-detect-a-blow-in-the-microphone-with-unity-and-ios – user3293557