2016-05-09 5 views
0
fs, s = wav.read('wave.wav') 

この信号44100ヘルツsampleing frquencyが、私はフロートにすることはできません scipy.signal.resample(s,s.size/5.525)が、2番目の要素を使用して8Khzのには、この信号をdonwnsampleしたいので、どのように我々は、音声信号をresmaplingため、この機能を使用することができていますか?どのようにして、scipy.signal.resampleを使用して44100〜8000 Hzの信号から音声信号をダウンサンプリングできますか?

scipy.signal.resampleを使用して、44100〜8000 Hzの音声信号をパイソンでダウンサンプリングできますか?

答えて

0

私はネイサン・ホワイトヘッドによって書かれたSWMixerモジュールから選んだこの:あなたはscipyのダウンロードを使用している場合

import numpy 

def resample(smp, scale=1.0): 
    """Resample a sound to be a different length 
    Sample must be mono. May take some time for longer sounds 
    sampled at 44100 Hz. 

    Keyword arguments: 
    scale - scale factor for length of sound (2.0 means double length) 
    """ 
    # f*ing cool, numpy can do this with one command 
    # calculate new length of sample 
    n = round(len(smp) * scale) 
    # use linear interpolation 
    # endpoint keyword means than linspace doesn't go all the way to 1.0 
    # If it did, there are some off-by-one errors 
    # e.g. scale=2.0, [1,2,3] should go to [1,1.5,2,2.5,3,3] 
    # but with endpoint=True, we get [1,1.4,1.8,2.2,2.6,3] 
    # Both are OK, but since resampling will often involve 
    # exact ratios (i.e. for 44100 to 22050 or vice versa) 
    # using endpoint=False gets less noise in the resampled sound 
    return numpy.interp(
     numpy.linspace(0.0, 1.0, n, endpoint=False), # where to interpret 
     numpy.linspace(0.0, 1.0, len(smp), endpoint=False), # known positions 
     smp, # known data points 
     ) 

そう、それはあなたがあまりにもnumpyのを持っていることを意味します。 scipyのダウンロードは、「MUST番号でない場合は、この、それは完璧に動作します。

+0

時間を経ること(すなわち、「スケール」<1)。 'smp'がダウンサンプリングされた信号のサンプリングレートの半分以上の周波数内容を持っている場合、その結果は、あまりにも低いレートでそれらの周波数をサンプリングすることから来るゴミを含みます。 –

+0

はい、そうですが、フィルタリングは補間の前に別々に行うことができます。そして、意図された使用はスピーチのためです。誰かが突然歌い始める場合を除き、それは保持されます。シンフォニーオーケストラを録音してダウンサンプリングした場合、ゴミは目立つことになります。他のごみは許容されます。 – Dalen

1

さて、別の解決策、リアルのためのscipyのダウンロードと、このいずれかを使用します。を求めただけで何。

これはのドキュメント文字列ですscipy.signal.resampleは():あなたが知っておくべきこととして

""" 
Resample `x` to `num` samples using Fourier method along the given axis. 

The resampled signal starts at the same value as `x` but is sampled 
with a spacing of ``len(x)/num * (spacing of x)``. Because a 
Fourier method is used, the signal is assumed to be periodic. 

Parameters 
---------- 
x : array_like 
    The data to be resampled. 
num : int 
    The number of samples in the resampled signal. 
t : array_like, optional 
    If `t` is given, it is assumed to be the sample positions 
    associated with the signal data in `x`. 
axis : int, optional 
    The axis of `x` that is resampled. Default is 0. 
window : array_like, callable, string, float, or tuple, optional 
    Specifies the window applied to the signal in the Fourier 
    domain. See below for details. 

Returns 
------- 
resampled_x or (resampled_x, resampled_t) 
    Either the resampled array, or, if `t` was given, a tuple 
    containing the resampled array and the corresponding resampled 
    positions. 

Notes 
----- 
The argument `window` controls a Fourier-domain window that tapers 
the Fourier spectrum before zero-padding to alleviate ringing in 
the resampled values for sampled signals you didn't intend to be 
interpreted as band-limited. 

If `window` is a function, then it is called with a vector of inputs 
indicating the frequency bins (i.e. fftfreq(x.shape[axis])). 

If `window` is an array of the same length as `x.shape[axis]` it is 
assumed to be the window to be applied directly in the Fourier 
domain (with dc and low-frequency first). 

For any other type of `window`, the function `scipy.signal.get_window` 
is called to generate the window. 

The first sample of the returned vector is the same as the first 
sample of the input vector. The spacing between samples is changed 
from dx to: 

    dx * len(x)/num 

If `t` is not None, then it represents the old sample positions, 
and the new sample positions will be returned as well as the new 
samples. 

""" 

、8000 Hzのは、あなたの信号の1秒は8000個のサンプルが含まれており、44100 Hzのために、それは1秒で44100サンプルが含まれていることを意味していることを意味し

次に、ちょうど計算あなたが8000Hzに必要なサンプル数をscipy.signal.resample()の第2引数として使用します。

あなたはネイサン・ホワイトヘッドは、私は他の回答(スケーリング)にcoppiedリサンプル機能で使用する方法、

を使用するか、私は低いが表示されていないすなわち

secs = len(X)/44100.0 # Number of seconds in signal X 
samps = secs*8000  # Number of samples to downsample 
Y = scipy.signal.resample(X, samps) 
関連する問題