更改声音文件的速度 [英] Changing speed of a sound file

查看:126
本文介绍了更改声音文件的速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望更改声音文件的速度,但是如何完成它却茫然无措。我假设在减慢速度的情况下必须进行某种类型的插值,但是不确定如何提高速度-可能是几个样本的平均值?此刻是否改变速度或音调并不重要,我想学习如何完成这两项,但至少希望完成其中一项。

I'm looking to change the speed of a sound file, but am at a loss as to how to accomplish it. I'm assuming that some type of interpolation has to take place in the case of slowing it down, but am unsure how to accomplish a speed up - perhaps an average of several samples? Whether it changes the tempo or pitch doesn't really matter at the moment, I'd like to learn how to accomplish both, but would like to at least accomplish one or the other to begin.

如果有人引用这些类型的运算背后的数学,将不胜感激!

If anyone has any references to the math behind these types of operations, they would be greatly appreciated!

谢谢,
Ben

Thanks, Ben

推荐答案

有两种方法可以加快声音文件的播放速度:

There are two options to speed up the playback of a sound file:


  • 提高采样率

  • 减少单位时间的采样数。

在这两种方法中,播放速度的提高都会使声音的音高发生相应的变化。

In either of these methods, the increase in playback speed will have a corresponding change in the pitch of the sound.

采样率

提高采样率将提高声音的播放速度。例如,从22 KHz的采样率变为44 KHz,将使播放声音的速度是原始声音的两倍。在这种方法中,原始采样数据保持不变-只需更改音频播放设置。

Increasing the sample rate will increase the playback speed of the sound. For example, going from a 22 KHz sampling rate to 44 KHz will make the playback sound twice as fast as the original. In this method, the original sampling data is unaltered -- only the audio playback settings need to be changed.

减少单位时间的采样数

在这种方法中,回放采样率保持不变,但样本数量减少了-有些样本被扔掉了。

In this method, the playback sampling rate is kept constant, but the number of samples are reduced -- some of the samples are thrown out.

使声音播放速度是原始速度的两倍的天真方法是删除所有其他采样,并以原始播放采样率进行播放。

The naive approach to make the playback of the sound be twice the speed of the original is to remove every other sample, and playback at the original playback sampling rate.

但是,使用这种方法会丢失一些信息,并且我希望音频中会引入一些伪像,所以这不是最理想的方法。

However, with this approach, some of the information will be lost, and I would expect that some artifacts will be introduced to the audio, so it's not the most desirable approach.

尽管我自己还没有尝试过,但是对样本进行平均以创建新样本的想法是一个很好的起点。这似乎意味着,不仅可以舍弃音频信息,还可以通过平均过程将其保留到一定程度。

Although I haven't tried it myself, the idea of averaging the samples to create a new sample to be a good approach to start with. This would seem to mean that rather than just throwing out audio information, it can be "preserved" to an extent by the averaging process.

,这是一段伪代码,可以使播放速度提高一倍:

As a rough idea of the process, here's a piece of pseudocode to double the speed of playback:

original_samples = [0, 0.1, 0.2, 0.3, 0.4, 0.5]

def faster(samples):
    new_samples = []
    for i = 0 to samples.length:
        if i is even:
            new_samples.add(0.5 * (samples[i] + samples[i+1]))
    return new_samples

faster_samples = faster(original_samples)

我还发布了一个问题的答案 ,在其中我详细介绍了可以执行的一些基本音频操作,因此也许也很有趣。

I've also posted an answered to the a question "Getting started with programmatic audio" where I went into some details about some basic audio manipulation that can be performed, so maybe that might be of interest as well.

这篇关于更改声音文件的速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆