1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# -*- coding: utf-8 -*- ## Copyright 2019 Trevor van Hoof and Jan Pijpers. ## Licensed under the Apache License, Version 2.0 ## Downloaded from https://janpijpers.com or https://gumroad.com/janpijpers ## See the license file attached or on https://www.janpijpers.com/script-licenses/ ''' Name: scipy wav file Description: Usually not a big fan of scipy and numpy cause of no Maya compatability. But still usefull as an example ''' from scipy.io import wavfile def trim_wav( originalWavPath, newWavPath , start, end ): ''' :param originalWavPath: the path to the source wav file :param newWavPath: output wav file * can be same path as original :param start: time in seconds :param end: time in seconds :return: ''' sampleRate, waveData = wavfile.read( originalWavPath ) startSample = int( start * sampleRate ) endSample = int( end * sampleRate ) wavfile.write( newWavPath, sampleRate, waveData[startSample:endSample]) wp = r"pathToWav.wav" trim_wav(wp, wp.replace(".wav", "_trimmed.wav"), 0,10) |