コード例 #1
0
def wsola_sample(sample, speed):
    '''Scales sample by speed'''
    sample = sample.reshape(1, len(sample))
    reader = ArrayReader(sample)
    writer = ArrayWriter(channels=1)
    tsm = wsola(1, speed=speed)
    tsm.run(reader, writer)
    return writer.data[0]
コード例 #2
0
def time_stretch(data, speed):
    data = data.reshape(1, -1)
    reader = ArrayReader(data)
    writer = ArrayWriter(channels=1)
    tsm = wsola(channels=1, speed=speed)
    tsm.run(reader, writer)
    output = np.ascontiguousarray(writer.data.T)
    output = output.flatten()
    return output
コード例 #3
0
ファイル: main_basic.py プロジェクト: Logtic/TSM_practice
def create_tsm(name, channels, parameters):
    """Create a TSM object given the method name and its parameters."""
    if name == "ola":
        return ola(channels, **parameters)
    if name == "wsola":
        return wsola(channels, **parameters)
    if name == "phasevocoder":
        return phasevocoder(channels, **parameters)

    raise ValueError("unknown TSM method: {}".format(name))
コード例 #4
0
    def create_tsm(self, channels):
        parameters = {}
        if self.frame_length > 0:
            parameters['frame_length'] = self.frame_length
        if self.synthesis_hop > 0:
            parameters['synthesis_hop'] = self.synthesis_hop
        if self.tolerance >= 0:
            parameters['tolerance'] = self.tolerance

        return wsola(channels, **parameters)
コード例 #5
0
ファイル: test_data.py プロジェクト: suldier/audiotsm
def create_tsm(name, channels, speed):
    """Create a TSM object given the method name and its parameters."""
    if name == "ola":
        return ola(channels, speed)
    if name == "wsola":
        return wsola(channels, speed)
    if name == "phasevocoder":
        return phasevocoder(channels, speed, phase_locking=PhaseLocking.NONE)
    if name == "phasevocoder_identity":
        return phasevocoder(channels, speed,
                            phase_locking=PhaseLocking.IDENTITY)

    raise ValueError("unknown TSM method: {}".format(name))
コード例 #6
0
def resampling(x, coef=1., fs=16000):
    fn_r, fn_w = tempfile.NamedTemporaryFile(
        mode="r", suffix=".wav"), tempfile.NamedTemporaryFile(mode="w",
                                                              suffix=".wav")

    sf.write(fn_r.name, x, fs, "PCM_16")
    with WavReader(fn_r.name) as fr:
        with WavWriter(fn_w.name, fr.channels, fr.samplerate) as fw:
            tsm = wsola(channels=fr.channels,
                        speed=coef,
                        frame_length=256,
                        synthesis_hop=int(fr.samplerate / 70.0))
            tsm.run(fr, fw)

    y = resample(librosa.load(fn_w.name)[0], len(x)).astype(x.dtype)
    fn_r.close()
    fn_w.close()

    return y
コード例 #7
0
ファイル: sine.py プロジェクト: suldier/audiotsm
"""
# pylint: disable=invalid-name

import numpy as np
import sounddevice as sd
from audiotsm import wsola
from audiotsm.io.array import ArrayReader, ArrayWriter


# The parameters of the input signal
length = 1  # in seconds
samplerate = 44100  # in Hz
frequency = 440  # an A4

# Generate the input signal
time = np.linspace(0, length, int(length * samplerate))
input_signal = np.sin(np.pi * frequency * time).reshape((1, -1))

# Run the TSM procedure
reader = ArrayReader(input_signal)
writer = ArrayWriter(channels=1)

tsm = wsola(channels=1, speed=0.5)
tsm.run(reader, writer)

# Play the output
# This example was written to show how to use an ArrayWriter. If you want to
# play the output of a TSM procedure you should use an
# audiotsm.io.stream.StreamWriter.
sd.play(np.ascontiguousarray(writer.data.T), samplerate, blocking=True)