gpt4 book ai didi

ios - 如何从 POVoiceHUD 播放录制的音频文件

转载 作者:行者123 更新时间:2023-11-29 03:53:08 25 4
gpt4 key购买 nike

我正在使用 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];
}

但是我收到错误不兼容的指针类型没有已知的类选择器

最佳答案

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

内部 View Vontroller.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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com