• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python audiolab.wavread函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中scikits.audiolab.wavread函数的典型用法代码示例。如果您正苦于以下问题:Python wavread函数的具体用法?Python wavread怎么用?Python wavread使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了wavread函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: main

def main():

    # import soundfile
    snd = wavread('trumpet.wav')[0]
    kick = wavread('kick.wav')[0]
    amb = wavread('amb.wav')[0]
    amb = amb * 0.8                 # reduce gain of this soundfile a little bit
    
    print len(amb)
    #low_demo(snd, 10., 500.)
    #high_demo(snd, 10000., 10.)
    #allpass_demo(snd, 1000, -find_c(1000., fs), find_c(1000., fs), 1.0)
    #iir_comb_demo(kick, 100, 0.5, -0.5)

    t = len(amb) / fs
    period = 1.0 / fs
    t_v = arange(0.0, t, period)
    delayTime = 2.0
    width = 1.0
    freq = 1
    breakPoint = (sin(2. * pi * freq * t_v))
    #breakPoint = linspace(1, -1, len(amb))

    #var_allpass_demo(snd, delayTime / 1000., width / 1000., -find_c(8000, fs), find_c(8000, fs), 1.0, breakPoint)
    #var_allpass_demo(amb, delayTime / 1000., width / 1000., 0.5, -0.5, 0.0, breakPoint)

    # flanger
    var_allpass_demo(amb, delayTime, width, 0.7, 0.7, 0.7, breakPoint)
开发者ID:slegroux,项目名称:slgDAFX,代码行数:28,代码来源:dafx_main.py


示例2: noise_reduce_test

def noise_reduce_test():
	sample = wavread('../../sounds/single-bloop-trimmed.wav')[0]
	noise = wavread('../../sounds/single-bloop-noise.wav')[0]
	sample = bandpass(sample,30000,50000)
	t0 = time.time()
	sample = noise_reduce(sample,noise,NoiseReduceSettings())
	print 'noise filter in time:', round(time.time() - t0,2)
	'''
开发者ID:idreyn,项目名称:robin,代码行数:8,代码来源:test_noisereduce.py


示例3: sound_wav

def sound_wav():
    clf()
    (snd, sampFreq, nBits) = audiolab.wavread('temp.wav')
    wave_form = []
    signal = snd[:,0]
    if (len(signal)) < 500000:
        timeArray = arange(0, float(len(signal)), 1)
        timeArray = timeArray / sampFreq
        wave_form = signal
    else:
        downsample_factor = len(signal) / 30000
        i = 0
        while i < len(signal):
            wave_form = wave_form + [signal[i]]
            i = i + downsample_factor
        timeArray = arange(0, float(len(wave_form)), 1)
        timeArray = timeArray * downsample_factor / sampFreq
    timeArray = timeArray * 1000
    plot(timeArray, wave_form, color='k')
    ylabel('Amplitude')
    xlabel('Time (ms)')
    savefig('wave_form.png', bbox_inches=0)
    # show()
# setup('skream.wav')
# sound_wav()
# teardown()
开发者ID:spencerhitch,项目名称:radiotape,代码行数:26,代码来源:sound_wave.py


示例4: __init__

 def __init__(self, filepath):
     
     self.filepath = filepath
     (self.audio_array, self.sample_rate, self.format) = wavread(filepath)
     self.name = os.path.basename(filepath)
     samples = len(self.audio_array)
     self.length = float(samples) / float(self.sample_rate)
开发者ID:jgoconnell,项目名称:hmosaic,代码行数:7,代码来源:models.py


示例5: wavread

def wavread(path):
    """
    Wrapper around scikits functions
    Returns: wavdata, sample rate, encoding type
    See pyaudiolab or scikits.audiolab for more information
    """
    return AUDIOLAB.wavread(path)
开发者ID:tbertinmahieux,项目名称:InfiniteListener,代码行数:7,代码来源:get_landmarks.py


示例6: test_bad_wavread

    def test_bad_wavread(self):
        """ Check wavread on bad file"""
        # Create a tmp audio file with non wav format, write some random data into it,
        # and check it can not be opened by wavread
        rfd, fd, cfilename   = open_tmp_file('pysndfiletest.wav')
        try:
            nbuff = 22050
            noise = 0.1 * N.random.randn(nbuff)

            # Open the copy file for writing
            format = audio_format('aiff', 'pcm16')
            b = Sndfile(cfilename, 'w', format, 1, nbuff)

            b.write_frames(noise)

            b.close()

            b = Sndfile(cfilename, 'r')
            rcnoise = b.read_frames(nbuff)
            b.close()

            try:
                rnoise  = wavread(cfilename)[0]
                raise Exception("wavread on non wav file succeded, expected to fail")
            except ValueError, e:
                pass
                #print str(e) + ", as expected"

        finally:
            close_tmp_file(rfd, cfilename)
开发者ID:LiberationFrequency,项目名称:BazzArch,代码行数:30,代码来源:test_matapi.py


示例7: computeFeaturesForFullSong

def computeFeaturesForFullSong(file_path, feature_list, pack_size):
    """
    Computes each of the features (must be full_song features) for the song recording.
    This method is used for one shot computation of a songs features.
    :param file_path:
    :param features:
    :param pack_size:
    :return: a tuple of values with length = len(features). Each item is the resulting feature value corresponding to features[].
    """

    # will hold the evaluated feature values
    feature_values = []

    raw_data, fs, enc = wavread(file_path)
    raw_chunks = chunks(raw_data, pack_size)

    for feature_name in feature_list:
        # print "Computing " + feature_name
        class_ = getattr(features, feature_name)
        if class_.requireFullSong is False: # ensure full song
            raise "Every feature must be a full song feature"

        feature = class_(raw_chunks)
        feature_values.append(feature.value)

    return feature_values
开发者ID:damianpolan,项目名称:Music-Genre-Classification,代码行数:26,代码来源:tools.py


示例8: convert_wav

def convert_wav(File, ofile):
    import scikits.audiolab as audiolab
    from scikits.samplerate import resample
    # lastest scikits.audiolab include sound record lib, based on python-alsaaudio
    # if you want make the down sample rate using scipy.signal
    #import scipy.signal

    #using audiolab to read wav file
    Signal, fs = audiolab.wavread(File)[:2]
    #changing the original sample rate to 16000fs fast mode
    Signal = resample(Signal, fr/float(fs), 'sinc_best')
     
    #changing sample rate from audio file using scipy this is a bit slow
    #Signal=scipy.signal.resample(Signal,int(round(len(Getsignal)*fr)/float(fs)),window=None)
     
    # file Format type
    fmt = audiolab.Format('flac', 'pcm16')
    nchannels   = 1
     
    # convert into the file .flac
    ofile =  audiolab.Sndfile(FileNameTmp, 'w', fmt, nchannels, fr)
     
    #writing in the file
    ofile.write_frames(Signal)
    #
    return ofile
开发者ID:chayanforyou,项目名称:arduinorobotcar,代码行数:26,代码来源:pyGoogleVoiceRC.py


示例9: gather_training_data

def gather_training_data(path=SAMPLE_PATH):
    instr_names = os.walk(path).next()[1]
    samples = dict()

    pitch_pattern = re.compile("([A-G][sb]?)(\d+)")

    # NOTE: Could potentially make subdirs for different qualities

    for instr in instr_names:
        #if instr not in ('guitar', 'trumpet'): continue
        instr_samples = []
        instr_sample_dir = "%s\%s" % (SAMPLE_PATH, instr)
        for samp in [f for f in os.listdir(instr_sample_dir) \
                if os.path.isfile(os.path.join(instr_sample_dir, f)) \
                and os.path.splitext(f)[1].lower() == ".wav"]:
            data, fs, enc = skal.wavread("%s\%s" % (instr_sample_dir, samp))

            matches = pitch_pattern.search(samp)
            assert matches is not None

            chroma, octave = matches.groups()
            chroma = canonical_chroma[chroma]

            # NOTE: It's quite possible that using a dictionary
            #       instead of a list will be helpful, but we'll
            #       cross that bridge when we get to it
            instr_samples.append( (data, chroma, octave) )

        samples[instr] = instr_samples

    return samples
开发者ID:jtcramer,项目名称:streaminstrumentseparation,代码行数:31,代码来源:training_plca.py


示例10: main

def main():
    """
    Main function for processing the specified soundfile through this reverb.
    """

    parser = argparse.ArgumentParser(description='Artificial Reverb')
    parser.add_argument('soundfile', help='audio file to process', type=validInput)        # the soundfile is the first agument, with parameter values to follow
    parser.add_argument('outfile', help='path to output file', type=validInput)
    parser.add_argument('-w', '--wetdry', default=0.2, type=float, help='amount of wet signal in the mix')
    parser.add_argument('-da', '--damping', default=0.25, type=float, help='amount of high frequency damping')
    parser.add_argument('-de', '--decay', default=0.4, type=float, help='amount of attentuation applied to signal to make it decay')
    parser.add_argument('-pd', '--predelay', default=30, type=float, help='amount of time before starting reverb')
    parser.add_argument('-b', '--bandwidth', default=0.6, type=float, help='amount of high frequency attentuation on input')
    parser.add_argument('-t', '--tankoffset', default=0, type=float, help='amount of time (ms) to increase the last tank delay time')

    # Parse the commandline arguments
    args = parser.parse_args()

    # Get the entire path and assign soundfile
    soundfilePath = os.path.join(os.getcwd(), args.soundfile)
    
    # From here on, x refers to the input signal
    x, sampleRate, wavType = wavread(soundfilePath)
    dry = x.copy()

    y = reverbTest(x, sampleRate, args.damping, args.decay, args.predelay, args.bandwidth, args.tankoffset)

    # Apply wet/dry mix
    output = dryWet(dry, y, args.wetdry)

    # Finally write the output file
    wavwrite(transpose(output), args.outfile, sampleRate)
开发者ID:GTCMTold,项目名称:plate-reverb,代码行数:32,代码来源:reverb.py


示例11: _analyse

    def _analyse(self, filepath):
        audio = to_mono(wavread(filepath)[0])
        audio = audio.astype('float32')
        
        w = Windowing(type = 'hann')
        fft = FFT() # this gives us a complex FFT
        c2p = CartesianToPolar() # and this turns it into a pair (magnitude, phase)
        hfc_detect = OnsetDetection(method = 'hfc')
        complex_detect = OnsetDetection(method = 'complex')
        rms_detect = RMS()
        spec = Spectrum()
        #pd = PitchDetection()
        flux = Flux()
        pool = Pool()
        #wap = WarpedAutoCorrelation()
        
    
        # let's get down to business
        print 'Computing onset detection functions...'
        for frame in FrameGenerator(audio, frameSize = self.frame_size,\
            hopSize = self.hop_size):
            mag, phase, = c2p(fft(w(frame)))
            spectrum = spec(w(frame))
            f = flux(spectrum)
            #pitch = pd(spectrum)
            pool.add('hfc', hfc_detect(mag, phase))
            pool.add('complex', complex_detect(mag, phase))
            pool.add('rms', rms_detect(frame))
            pool.add('flux', f)
            #pool.add('pitch', pitch[0])
        #print pool['pitch']
        #pool.add('autoc', wap(pool['pitch']))
     

        return pool, audio
开发者ID:jgoconnell,项目名称:hmosaic,代码行数:35,代码来源:segment.py


示例12: estimate_f0s

    def estimate_f0s(self, audio_path):
        if not os.path.exists(audio_path):
            raise ValueError('Invalid audio path')

        x, fs, _ = wavread(audio_path)

        # make x mono if stereo
        if x.ndim > 1:
            _, n_channels = x.shape
            x = x.sum(axis=1)/n_channels

        X = self._stft(x, fs)

        # Section 2.1 Spectrally whiten the signal to suppress timbral information
        Y = self._spectral_whitening(X, fs)

        # perform iterative estimation of the fundamental periods in the audio file
        f0_estimations = self._iterative_est(Y, fs)
        
        # get notes which correspond to these frequency estimates
        notes = []
        for frame_ests in f0_estimations:
            notes.append([self._freq_to_note(f) for f in frame_ests])

        return f0_estimations, notes
开发者ID:bagustris,项目名称:multi-f0-estimation,代码行数:25,代码来源:f0estimate.py


示例13: loadFiles

def loadFiles(path):
	"""reads wave files from path and returns dictionary with fields:
        - "name" - name of file
        - "nameGender" - a sex readed from filename
        - "signal" - numpy array with sound signal readed from file
        - "sampleRate" - sample rate of the file

        and dictionary that contains numbers of male and female voices
	"""
	print "reading files..."

	files = [ f for f in listdir(path) if isfile(join(path,f)) and splitext(f)[1] == ".wav" ]

	samples = []
	maleCount = 0
	femaleCount = 0
	for f in files:
		p = path + '/' + f

		print "...", f
		data,rate,encoding=wavread(p)
		sig=[mean(d) for d in data]    
		samples.append({'name': f, 'nameGender': f[-5:-4], 'signal': sig, 'sampleRate': rate})
        
		if f[-5:-4] == "M":
			maleCount += 1
		else:
			femaleCount += 1
    
	counters = {"maleCount":maleCount, "femaleCount":femaleCount}
	return samples, counters
开发者ID:rybmat,项目名称:gender_recognition,代码行数:31,代码来源:glosy.py


示例14: open_wav_audiolab

 def open_wav_audiolab(self, filename):
     #http://scikits.appspot.com/audiolab
     from scikits.audiolab import wavread
     results, sample_frequency,encoding = wavread(filename)
     self.sample_rate = sample_frequency
     print 'Sample Rate is ', sample_frequency
     return results, self.sample_rate
开发者ID:tammyyang,项目名称:audio_analysis,代码行数:7,代码来源:analysis.py


示例15: normalize_target_audio

def normalize_target_audio(input_file='moviehires_endpos_beta02.imatsh.wav', 
                           sources_expr='/home/mkc/Music/GoldbergVariations/*48_1.wav', write_me=False, amp_factor=0.5, proc_audio=True):
    """
    Per-variation normalization of concatenated imatsh file using individual sources as locators
    Assumes that the input_file and the source_dir have the same sample rate
    inputs:
        input_file  - the file to be processed (locally normalized)
        sources_expr- regular expression for input files
        write_me    - write output files when true [False]
        amp_factor  - amplitude change factor (proportion of full scale normalization) [0.5]
        proc_audio  - whether to process target audio using source audio info [1]
    outputs:
        sample_locators - sample locators for each variation
        audio_summaries - min, max, rms values for each variation        
    output files:
        output_file = {input_file_stem}+'norm.'+{input_ext}
    """
    # Compute min, max, rms per source file
    flist = glob.glob(sources_expr)
    flist.sort()
    sample_locators = [0]
    audio_summaries = []
    ext_pos = input_file.rindex('.')
    outfile_stem, ext = input_file[:ext_pos], input_file[ext_pos+1:]
    for i,f in enumerate(flist):
        x,sr,fmt = skaud.wavread(f)
        print f, sr, fmt
        if(len(x.shape)>1):
            x = x[:,0] # Take left-channel only
        sample_locators.extend([len(x)])
        audio_summaries.append([max(abs(x)), np.sqrt(np.mean(x**2))])
        if proc_audio:
            y,sr_y,fmt_y = skaud.wavread(input_file, first=np.cumsum(sample_locators)[-2], last=sample_locators[-1])
            if sr != sr_y:
                raise ValueError("input and source sample rates don't match: %d,%d"%(sr,sr_y))
            audio_summaries.append([max(abs(y[:,0])), np.sqrt(np.mean(y[:,0]**2))])
            max_val = audio_summaries[-1][0]
            rms_val = audio_summaries[-1][1]
            norm_cf = amp_factor / max_val + (1 - amp_factor)
            outfile = outfile_stem+'_%02d.%s'%(i+1,ext)
            max_amp_val = norm_cf * max_val
            rms_amp_val = norm_cf * rms_val
            print '%s: nrm=%05.2fdB, peak=%05.2fdB, *peak=%05.2fdB, rms=%05.2fdB, *rms=%05.2fdB'%(
                outfile, dB(norm_cf), dB(max_val), dB(max_amp_val), dB(rms_val), dB(rms_amp_val))
            if(write_me):
                skaud.wavwrite(norm_cf*y, outfile, sr, fmt)
    return np.cumsum(sample_locators), np.array(audio_summaries)
开发者ID:bregmanstudio,项目名称:BLAST,代码行数:47,代码来源:onemillionseconds.py


示例16: train_codebook

def train_codebook(basedirectory,
                   spectral,
                   desired_fs,
                   clfs,
                   n_samples):
    """Train the codebooks.

    Arguments:
    :param basedirectory: root directory of the audio corpus
    :param spectral:
      Spectral feature extraction.
      Object should be picklable and implement the
      \c Spectral abc; i.e. provide a \c transform method.
    :param clfs:
      list of clusterers. valid clusterers have a \c fit method
      and a \c predict method. optionally, for soft vq, also implement
      a \c predict_proba method.
    :param n_samples:
      number of spectral frames to sample from the audio corpus.
    :returns:
      a list of Codebook objects, of same length as the output of spectral_func
    """
    wavs = list(rglob(basedirectory, '*.wav'))
    np.random.shuffle(wavs)

    inds = None
    idx = 0
    X = None
    for i, wav in enumerate(wavs):
        if i % 10 == 0 and i > 0:
            print 'samples: {3}/{4}; loading file: {0} ({1}/{2})'.format(
                wavs[i],
                i+1,
                len(wavs),
                X.shape[0],
                n_samples
            )
        sig, fs, _ = audiolab.wavread(wav)
        start, stop = trim_silence(sig, fs)
        specs = spectral.transform(samplerate.resample(sig[start:stop],
                                                       desired_fs/fs,
                                                       'sinc_best'))
        if inds is None:
            inds = [0] + list(np.cumsum([spec.shape[1] for spec in specs]))
        spec = np.hstack(specs)
        if idx + spec.shape[0] >= n_samples:
            spec = spec[:n_samples - idx, :]
        if X is None:
            X = spec
        else:
            X = np.vstack((X, spec))
        idx += spec.shape[0]
        if idx >= n_samples:
            break

    cdbs = [Codebook(clf) for clf in clfs]
    for i, cdb in enumerate(cdbs):
        cdb.train(X[:, inds[i]:inds[i+1]])
    return cdbs
开发者ID:mwv,项目名称:hac,代码行数:59,代码来源:train_codebook.py


示例17: analyzeWAV

def analyzeWAV(inputFile):
    """
    inputFile = .wav audiofile
    returns array of audiodata and the sampling rate
    """
    data, fs, nbits = audiolab.wavread(inputFile)
    samplingRate = fs
    return [data, samplingRate]
开发者ID:nlintz,项目名称:SigsysFinal,代码行数:8,代码来源:analyzeWAV.py


示例18: set_filepath

 def set_filepath(self, path):
     """
         When passed a valid wav file into ``path``, this file
         is read and the current data is replaced by this new data.
     """
     self.filepath = path
     (self.data, self.sample_rate, self.format) = wavread(path)
     self.recalculate()
开发者ID:jgoconnell,项目名称:hmosaic,代码行数:8,代码来源:models.py


示例19: loadSignal

def loadSignal(fileName):
	try:
		x, Fs, encFmt = al.wavread(fileName)
	except IOError:
		print('Could not import file "%s"' % sigPath)
		return None

	return (x, Fs)
开发者ID:d-unknown-processor,项目名称:acoustic-simulator,代码行数:8,代码来源:prepare-impulse-responses.py


示例20: wavread

def wavread(filename):
    """
    wav, fs, nbits = wavread(filename)

    Read file FILENAME. WAV is a numpy array, FS is the sampling rate,
    and NBITS is the bit depth.
    """
    return audiolab.wavread(filename)
开发者ID:zangsir,项目名称:pymir,代码行数:8,代码来源:mir.py



注:本文中的scikits.audiolab.wavread函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python audiolab.Sndfile类代码示例发布时间:2022-05-27
下一篇:
Python common._函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap