gpt4 book ai didi

ios - Novocaine - 如何循环播放文件? (iOS)

转载 作者:行者123 更新时间:2023-11-29 13:25:43 27 4
gpt4 key购买 nike

我正在使用 alexbw 的 Novocaine Novocaine对于我的音频项目。

我正在使用此处的示例代码来读取文件。文件播放没有问题。我想用循环之间的间隙循环播放这段录音 - 关于如何做到这一点有什么建议吗?

谢谢。

码头。

// AUDIO FILE READING OHHH YEAHHHH
// ========================================

NSArray *pathComponents = [NSArray arrayWithObjects:
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
@"testrecording.wav",
nil];
NSURL *inputFileURL = [NSURL fileURLWithPathComponents:pathComponents];
NSLog(@"URL: %@", inputFileURL);

fileReader = [[AudioFileReader alloc]
initWithAudioFileURL:inputFileURL
samplingRate:audioManager.samplingRate
numChannels:audioManager.numOutputChannels];

[fileReader play];
[fileReader setCurrentTime:0.0];
//float duration = fileReader.getDuration;

[audioManager setOutputBlock:^(float *data, UInt32 numFrames, UInt32 numChannels)
{
[fileReader retrieveFreshAudio:data numFrames:numFrames numChannels:numChannels];
NSLog(@"Time: %f", [fileReader getCurrentTime]);

}];

最佳答案

这对我有用:

[audioManager setOutputBlock:^(float *data, UInt32 numFrames, UInt32 numChannels)
{
if( ![fileReader playing] ){

// [fileReader release]; // for some reason this is causing an error, but I assume if you don´t do it, it will eventually cause a memory problem
// fileReader = nil;

[self playSound];
} else {
[fileReader retrieveFreshAudio:data numFrames:numFrames numChannels:numChannels];
NSLog(@"Time: %f", [fileReader getCurrentTime]);
}
}];

- (void) playSound
{
NSArray *pathComponents = [NSArray arrayWithObjects:
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
@"testrecording.wav",
nil];
NSURL *inputFileURL = [NSURL fileURLWithPathComponents:pathComponents];
NSLog(@"URL: %@", inputFileURL);

fileReader = [[AudioFileReader alloc]
initWithAudioFileURL:inputFileURL
samplingRate:audioManager.samplingRate
numChannels:audioManager.numOutputChannels];

[fileReader play];
[fileReader setCurrentTime:0.0];
//float duration = fileReader.getDuration;
}

关于ios - Novocaine - 如何循环播放文件? (iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13189251/

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