iPhone 上即时语音播放的最佳 API?

发布于 2024-11-07 20:48:37 字数 204 浏览 2 评论 0原文

我想做的事情:

  • iPhone就继续监听语音输入通道
  • 一旦用户说话(录音音量>一定级别),
  • 一旦用户停止说话(录音音量静音一秒), iPhone就开始录音
  • (录音音量静音一秒)
  • iPhone回放录音

哪个iPhone我应该研究 API 或示例代码吗?谢谢!

What I am trying to do:

  • iPhone keep monitoring the voice input channel
  • once the user speaks (recording sound volume > certain level)
  • iPhone starts recording
  • once the use stop speaking (recording volume silence for one second)
  • iPhone plays back the recording

Which iPhone API or sample code should I look into? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遗失的美好 2024-11-14 20:48:37

你需要的是 AVFoundation。要使用它:

  1. 将 AVFoundation.framework 添加到您的项目中,
  2. 使您的视图控制器符合 AVAudioRecorderDelegate、AVAudioPlayerDelegate,一个用于录制,另一个用于播放

以下代码用于录制:

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *err = nil;
[audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];
[audioSession setActive:YES error:&err];
NSMutableDictionary *settings = [[NSMutableDictionary alloc] init];
[settings setValue: [NSNumber numberWithInt:kAudioFormatMPEGLayer3] forKey:AVFormatIDKey];
[settings setValue: [NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; 
[settings setValue: [NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
[settings setValue: [NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[settings setValue: [NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[settings setValue: [NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
NSURL *url = [NSURL fileURLWithPath: filepath];
recorder = [[ AVAudioRecorder alloc] initWithURL:url settings:settings error:&err];
[settings release];
[recorder setDelegate:self];
[recorder prepareToRecord];
[recorder record];

另外,您需要实现 - (void)audioRecorderDidFinishRecording:(AVAudioRecorder *) 记录器成功:(BOOL)标志释放记录器。

请在此处查看更多详细信息:http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/00_Introduction.html#//apple_ref/doc/uid/TP40010188

What you need is AVFoundation. To use it:

  1. Adding AVFoundation.framework to your project
  2. conform your view controller to AVAudioRecorderDelegate, AVAudioPlayerDelegate, one for recording, another one for playing

Following piece of code is for recording:

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *err = nil;
[audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];
[audioSession setActive:YES error:&err];
NSMutableDictionary *settings = [[NSMutableDictionary alloc] init];
[settings setValue: [NSNumber numberWithInt:kAudioFormatMPEGLayer3] forKey:AVFormatIDKey];
[settings setValue: [NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; 
[settings setValue: [NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
[settings setValue: [NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[settings setValue: [NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[settings setValue: [NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
NSURL *url = [NSURL fileURLWithPath: filepath];
recorder = [[ AVAudioRecorder alloc] initWithURL:url settings:settings error:&err];
[settings release];
[recorder setDelegate:self];
[recorder prepareToRecord];
[recorder record];

Addtionally, you need to implement - (void)audioRecorderDidFinishRecording:(AVAudioRecorder *) recorder successfully:(BOOL)flag to release the recorder.

Please see more details here: http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/00_Introduction.html#//apple_ref/doc/uid/TP40010188

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文