gpt4 book ai didi

iphone - 如何查找音频文件长度(以秒为单位)

转载 作者:太空狗 更新时间:2023-10-30 03:46:19 24 4
gpt4 key购买 nike

( Objective-C )仅使用简单的 AudioServicesPlaySystemSoundID 及其对应项,但我无法在文档中找到是否已经有查找音频文件长度的方法。

我知道有 AudioServicesGetPropertyInfo,但它似乎返回一个字节缓冲区 - 音频文件是否将它们的长度嵌入到自身中,我可以用它提取它?

或者是否有基于比特率 * 文件大小的公式来转换为时间长度?

mIL3S

www.milkdrinkingcow.com

最佳答案

根据 Google 的快速搜索,有一个公式:

length-of-time (duration in seconds) = fileSize (in bytes) / bit-rate (bits/secs)*8

您使用系统声音服务播放声音有什么特别的原因吗?

如果你使用 AVAudioPlayer 来处理你的声音,你可以这样做:

AVAudioPlayer * sound = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil];
sound.delegate = self;
sound.volume = 1;
NSLog([NSString stringWithFormat:@"%f", sound.duration]);

关于iphone - 如何查找音频文件长度(以秒为单位),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4630176/

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