iPhone SDK:使用核心音频AVAudioPlayer更改播放速度

发布于 2024-08-25 12:56:59 字数 173 浏览 2 评论 0原文

我希望能够以 1.5 倍或 2.0 倍速度播放使用 AVAudioRecorder 录制的音频。我在 AVAudioPlayer 中没有看到任何支持这一点的内容。我希望获得一些有关如何使用 iPhone 3.x SDK 实现此目的的建议(如果可能的话还提供代码)。我并不太关心降低音调以补偿播放速度的提高,但能够这样做将是最佳选择。

I'd like to be able to play back audio I've recorded using AVAudioRecorder @ 1.5x or 2.0x speed. I don't see anything in AVAudioPlayer that will support that. I'd appreciate some suggestions, with code if possible, on how to accomplish this with the iPhone 3.x SDK. I'm not overly concerned with lowering the pitch to compensate for increased playback speed, but being able to do so would be optimal.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

臻嫒无言 2024-09-01 12:56:59

如果您播放得更快,更改采样率应该就像录音机一样。一切都变得更高调。为了保持音调相同,您需要设置一个包含 AUPitch 效果的音频单元图表,并按照与增加采样率相同的比率降低音调。

Changing the sample rate should work just like a tape recorder would if you played it faster. Everything becomes higher in pitch. To keep the pitch the same, you would need to set up an Audio Unit graph that includes the AUPitch effect, and lower the pitch by the same ratio that you increase the sample rate by.

贪了杯 2024-09-01 12:56:59

请参阅此问题。换句话说,您必须使用不同的 API,例如音频队列服务。如果您想尝试简单的破解,可以尝试将音频文件的采样率属性加倍。但它可能不会起作用。另外,请注意,在保持相同音调的情况下调整播放速度对 CPU 的要求相当高。您需要使用一种名为“时间拉伸”的可用技术。另外,如果你现在还没有意识到,在 iPhone 上使用音频做复杂的事情是一个很大的痛苦,因为 Apple 的文档通常要么非常糟糕,要么根本不存在。

See this question. In other words, you'll have to use a different API like Audio Queue Services. If you want to try a simple hack, you can try doubling the sample rate property of the audio file. It probably won't work though. Also, be warned that it is fairly CPU demanding to adjust the playback speed while keeping the same pitch. You'll need to use a one of the available techniques called "time stretching". Also, in case you haven't realized it by now, doing complicated things with audio on the iPhone is a major pain because Apple's documentation is generally either very bad or nonexistent.

听你说爱我 2024-09-01 12:56:59

如果你想更快或更慢地播放音频,avAudioPlayer中有一个内置方法。您是否尝试过 AudioPlayer Rate 属性?在 Swift 中会是这样的 -

    audioP = try! AVAudioPlayer(contentsOf: URL(fileURLWithPath: selectedPath), fileTypeHint: "caf")
    audioP.enableRate = true
    audioP.prepareToPlay()
    audioP.rate = 1.5
    audioP.play()

If you want to play audio faster or slower, there is a build-in method in avAudioPlayer. Have you tried AudioPlayer Rate property ? in Swift it will be like this -

    audioP = try! AVAudioPlayer(contentsOf: URL(fileURLWithPath: selectedPath), fileTypeHint: "caf")
    audioP.enableRate = true
    audioP.prepareToPlay()
    audioP.rate = 1.5
    audioP.play()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文