0

我使用控件在应用程序 POVoiceHUD 中录制语音。

https://github.com/polatolu/POVoiceHUD

我似乎错过了让文件播放/检索录制的音频的东西。演示项目不包括播放存储在[self.voiceHud startForFilePath:[NSString stringWithFormat:@"%@/Documents/MySound.caf", NSHomeDirectory()]];

我试过使用:

- (IBAction)play:(id)sender {

NSLog(@"playRecording");
// Init audio with playback capability
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];

NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/recordTest.caf", [[NSBundle mainBundle] resourcePath]]];
NSError *error;
_voiceHud = [[POVoiceHUD alloc] initWithContentsOfURL:url error:&error];
[_voiceHud play];
}

但是我收到错误incompatible pointer type,并且no known class selector

4

1 回答 1

1

这里 POVoiceHUD 文件负责录制你的音频文件。要播放这个录制的文件,您需要在 viewVontroller.h & .m 以及 POVoiceHUD.h & .m 中添加一些代码行

试试这个代码

在 POVoiceHUD.h 中包含这一行

 AVAudioPlayer *player;

 - (void)playRecording:(NSURL*)_url;

POVoiceHUD.m

- (void)playRecording:(NSURL*)_url {
    [self cancelRecording];

    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    [audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];

    NSError *error;

    player = [[AVAudioPlayer alloc] initWithContentsOfURL:_url error:&error];
    [player prepareToPlay];
    [player play];
}

内部视图Vontroller.h

- (IBAction)btnRecordTapped:(id)sender;
- (IBAction)btnPlayTapped:(id)sender;

视图控制器.m

- (IBAction)btnRecordTapped:(id)sender {

        [self.voiceHud startForFilePath:[NSString stringWithFormat:@"%@/Documents/MySound.caf", NSHomeDirectory()]];
}

- (IBAction)btnPlayTapped:(id)sender
{
    [self.voiceHud cancelRecording];

    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    [audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];

    NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/Documents/MySound.caf", NSHomeDirectory()]];

    [self.voiceHud playRecording:url];
}

我希望它可以帮助你。

于 2013-05-30T10:23:21.997 回答