我正在使用控件在应用程序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 typeno known class selector

最佳答案

在这里,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];
}


内部viewVontroller.h

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


ViewController.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];
}


希望对您有帮助。

关于ios - 如何从POVoiceHUD播放录制的音频文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16833416/

10-11 14:52