我正在将应用程序中的单个单词语音录制到 .wav 文件中
录制内容时遇到问题。例如,如果我记录自己说:“明天”,实际的 .wav 文件将记录“明天”或类似的内容。
我通过 http post 发送语音文件,以便听到服务器端录制的内容。我不知道如何轻松地听到我在 iphone 上录制的内容。
以下是应用程序的一些代码片段。
我将衷心感谢您的帮助 :)
NSArray *pathComponents = [NSArray arrayWithObjects:
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
@"MyAudioMemo.wav",
nil];
NSURL *outputFileURL = [NSURL fileURLWithPathComponents:pathComponents];
// Setup audio session
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
// Define the recorder setting
NSDictionary *recordSetting = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithFloat: 8000.0],AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatLinearPCM],AVFormatIDKey,// kAudioFormatLinearPCM
[NSNumber numberWithInt:16],AVLinearPCMBitDepthKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
[NSNumber numberWithBool:NO],AVLinearPCMIsBigEndianKey,
[NSNumber numberWithBool:NO],AVLinearPCMIsFloatKey,
[NSNumber numberWithInt: AVAudioQualityMedium],AVEncoderAudioQualityKey,nil];
// Initiate and prepare the recorder
NSError * error;
m_recorder = [[AVAudioRecorder alloc] initWithURL:outputFileURL settings:recordSetting error:&error];
if (error){
NSLog(@"Error init recorder%@", error.description);
[self setError:@"Failed to init recorder"];
}
m_recorder.delegate = self;
m_recorder.meteringEnabled = YES;
[m_recorder prepareToRecord];
……
- (void) startRecord{
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setActive:YES error:nil];
// Start recording
[m_recorder record];
[self.RecordPauseButton setTitle:@"Stop" forState:UIControlStateNormal];
}
- (void) stopRecord{
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setActive:NO error:nil];
// Stop Recording
[m_recorder stop];
[self.RecordPauseButton setTitle:@"Record" forState:UIControlStateNormal];
if (!self.ResultsViewController){
self.ResultsViewController = [[ResultsViewController alloc] initWithNibName:@"ResultsViewController" bundle:nil];
}
[NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:@selector(callProxyAndMoveScreen:)
userInfo:nil
repeats:NO];
[self.RecordPauseButton setEnabled:NO];
[self enterWaitState];
}
- (void) callProxyAndMoveScreen: (NSTimer *)timer{
self.ResultsViewController.SearchResults = [tusearchProxy searchWithVoice:[m_recorder url]];
[self.navigationController pushViewController:self.ResultsViewController animated:YES];
[self exitWaitState];
}