我有一个应用程序可以重复你所说的话,但是,我希望我可以让它降低或提高音调,而不是仅仅重复你自己的声音,这可能吗?
方法在这里;
-(void)playOnMainThread:(id)param
{
if (!outUrl) {
return;
}
player = [[AVAudioPlayer alloc] initWithContentsOfURL:recorder.url error:&error];
if (error)
NSLog(@"AVAudioPlayer error %@, %@", error, [error userInfo]);
player.delegate = self;
[player setVolume:10.0];
[player play];
}
最佳答案
所以这就是它的完成方式。您需要做一些事情才能开始
首次导入<AVFoundation/AVFoundation.h>
然后在.h文件中
AVAudioEngine *audioEngine;
AVAudioPlayerNode *playerNode;
AVAudioFile *avAudioFile;
AVAudioUnitTimePitch *pitch;
AVAudioMixerNode *mixer;
你将需要这些东西。
然后在.m文件中
-(void)allocInitRecorders
{
audioEngine = [[AVAudioEngine alloc] init];
playerNode = [[AVAudioPlayerNode alloc] init];
pitch = [[AVAudioUnitTimePitch alloc] init];
mixer = [[AVAudioMixerNode alloc] init];
[audioEngine stop];
[playerNode stop];
[audioEngine reset];
}
-(void)emptytheRecorders
{
audioEngine = nil;
playerNode = nil;
}
-(void)attachingNodes
{
[audioEngine attachNode:playerNode];
[audioEngine attachNode:pitch];
mixer = [audioEngine mainMixerNode];
[audioEngine connect:playerNode to:pitch format:[avAudioFile processingFormat]];
[audioEngine connect:pitch to:mixer format:[avAudioFile processingFormat]];
}
-(NSString *)filePathOfCollaboratedAudio
{
NSString* filePath = [[NSBundle mainBundle] pathForResource:@"Recording"
ofType:@"m4a"];
return filePath;
}
-(void)playAudio
{
NSError *err = nil;
[self emptytheRecorders];
[self allocInitRecorders];
[self attachingNodes];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:[self filePathOfCollaboratedAudio]];
if (fileExists)
{
avAudioFile = [[AVAudioFile alloc] initForReading:[NSURL URLWithString:[self filePathOfCollaboratedAudio]] error:&err];
}
pitch.pitch = 1000;
[audioEngine prepare];
[audioEngine startAndReturnError:&err];
NSError *error;
AVAudioPCMBuffer *buffer = [[AVAudioPCMBuffer alloc] initWithPCMFormat:avAudioFile.processingFormat frameCapacity:(AVAudioFrameCount)avAudioFile.length];
[avAudioFile readIntoBuffer:buffer error:&error];
[playerNode scheduleBuffer:buffer atTime:nil options:AVAudioPlayerNodeBufferInterruptsAtLoop completionHandler:^{
}];
if (err != nil) {
NSLog(@"An error occured");
}
else
{
[playerNode play];
}
}
然后调用该方法
[self playAudio];
大功告成
关于ios - 使用 AVAudioPlayer 更改音高,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43229110/