Пример #1
0
def fradosify(path, outfp, delta, pitchmin=70, pitchmax=400, threshold=0.7):
    print >> sys.stderr, 'reading: %r' % path
    ratio = pow(2, delta / 12.0)
    src = WaveReader(path)
    if src.nchannels != 1: raise ValueError('invalid number of channels')
    if src.sampwidth != 2: raise ValueError('invalid sampling width')
    contour = PitchContour(src.framerate,
                           pitchmin=pitchmin,
                           pitchmax=pitchmax,
                           threshold=threshold)

    dst = WaveWriter(outfp, framerate=src.framerate)

    nframes = src.nframes
    buf = src.readraw(nframes)
    contour.reset()
    contour.load(buf, nframes)

    def f(t):
        x = contour.getavg(t)
        if x != 0:
            x = int(x * ratio)
        return x

    dst.writeraw(psola(buf, src.framerate, contour.getsrc, f, contour.wmin))

    src.close()
    dst.close()
    return
Пример #2
0
def fradosify(path, outfp, delta,
              pitchmin=70, pitchmax=400, threshold=0.7):
    print >>sys.stderr, 'reading: %r' % path
    ratio = pow(2, delta/12.0)
    src = WaveReader(path)
    if src.nchannels != 1: raise ValueError('invalid number of channels')
    if src.sampwidth != 2: raise ValueError('invalid sampling width')
    contour = PitchContour(
        src.framerate,
        pitchmin=pitchmin, pitchmax=pitchmax,
        threshold=threshold)

    dst = WaveWriter(outfp, framerate=src.framerate)

    nframes = src.nframes
    buf = src.readraw(nframes)
    contour.reset()
    contour.load(buf, nframes)
    def f(t):
        x = contour.getavg(t)
        if x != 0:
            x = int(x*ratio)
        return x
    dst.writeraw(psola(buf, src.framerate, contour.getsrc, f, contour.wmin))
    
    src.close()
    dst.close()
    return
Пример #3
0
 def write(self, cur, path, force=False):
     if not force and os.path.exists(path):
         raise WavEdError('File exists: %r' % path)
     nframes = cur.get_length()
     fp = open(path, 'wb')
     writer = WaveWriter(fp,
                         nchannels=self._wav.nchannels,
                         sampwidth=self._wav.sampwidth,
                         framerate=self._wav.framerate)
     self._wav.seek(cur.start)
     (_, data) = self._wav.readraw(nframes)
     writer.writeraw(data)
     writer.close()
     fp.close()
     print('Written: %r, rate=%d, frames=%d, duration=%.3f' %
           (path, writer.framerate, nframes,
            nframes / float(writer.framerate)))
     return
Пример #4
0
 def write(self, cur, path, force=False):
     if not force and os.path.exists(path):
         raise WavEdError('File exists: %r' % path)
     nframes = cur.get_length()
     fp = open(path, 'wb')
     writer = WaveWriter(fp,
                         nchannels=self._wav.nchannels,
                         sampwidth=self._wav.sampwidth,
                         framerate=self._wav.framerate)
     self._wav.seek(cur.start)
     (_,data) = self._wav.readraw(nframes)
     writer.writeraw(data)
     writer.close()
     fp.close()
     print ('Written: %r, rate=%d, frames=%d, duration=%.3f' %
            (path, writer.framerate, nframes,
             nframes/float(writer.framerate)))
     return