diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..8b30580 --- /dev/null +++ b/setup.py @@ -0,0 +1,15 @@ +from setuptools import setup, find_packages + +setup( + name='python-world', + version='0.0.2', + description='Line-by-line implementation of the WORLD vocoder (Matlab, C++) in python.', + url='https://github.com/tuanad121/Python-WORLD', + packages=find_packages(), + install_requires=[ + 'numpy', + 'scipy', + 'matplotlib', + 'numba', + ] +) \ No newline at end of file diff --git a/world/cheaptrick.py b/world/cheaptrick.py index f5a52b9..2f5abb3 100644 --- a/world/cheaptrick.py +++ b/world/cheaptrick.py @@ -88,7 +88,7 @@ def calculate_windowed_waveform(x: np.ndarray, fs: int, f0: float, temporal_posi base_index = np.arange(-half_window_length, half_window_length + 1) index = int(temporal_position * fs + 0.501) + 1.0 + base_index safe_index = np.minimum(len(x), np.maximum(1, round_matlab(index))) - safe_index = np.array(safe_index, dtype=np.int) + safe_index = np.array(safe_index, dtype=np.int_) # wave segments and set of windows preparation segment = x[safe_index - 1] diff --git a/world/d4c.py b/world/d4c.py index ceae14d..9f0ac21 100644 --- a/world/d4c.py +++ b/world/d4c.py @@ -96,7 +96,7 @@ def get_windowed_waveform(x: np.ndarray, fs: int, current_f0: float, base_index = np.arange(-half_window_length, half_window_length + 1) index = int(current_position * fs + 0.501) + 1.0 + base_index safe_index = np.minimum(len(x), np.maximum(1, round_matlab(index))) - safe_index = np.array(safe_index, dtype=np.int) + safe_index = np.array(safe_index, dtype=np.int_) # wave segments and set of windows preparation segment = x[safe_index - 1] time_axis = base_index / fs / half_length + \ diff --git a/world/d4cRequiem.py b/world/d4cRequiem.py index 0c7afe0..701102c 100644 --- a/world/d4cRequiem.py +++ b/world/d4cRequiem.py @@ -77,7 +77,7 @@ def get_windowed_waveform(x: np.ndarray, fs: int, current_f0: float, base_index = np.arange(-half_window_length, half_window_length + 1) index = int(current_position * fs + 0.501) + 1.0 + base_index safe_index = np.minimum(len(x), np.maximum(1, round_matlab(index))) - safe_index = np.array(safe_index, dtype=np.int) + safe_index = np.array(safe_index, dtype=np.int_) # wave segments and set of windows preparation segment = x[safe_index - 1] time_axis = base_index / fs / half_length + \ diff --git a/world/dio.py b/world/dio.py index 87029b5..8b6c9e7 100644 --- a/world/dio.py +++ b/world/dio.py @@ -78,7 +78,7 @@ def get_spectrum(x, fs, lowest_f0): fft_size = 2 ** math.ceil(math.log(np.size(x) + int(fs / lowest_f0 / 2 + 0.5) * 4,2)) #low-cut filtering cutoff_in_sample = int(fs / 50 + 0.5) - low_cut_filter = signal.hanning(2 * cutoff_in_sample + 3)[1:-1] # remove zeros at starting and ending + low_cut_filter = signal.windows.hann(2 * cutoff_in_sample + 3)[1:-1] # remove zeros at starting and ending low_cut_filter = -low_cut_filter / np.sum(low_cut_filter) low_cut_filter[cutoff_in_sample] = low_cut_filter[cutoff_in_sample] + 1 low_cut_filter = np.r_[low_cut_filter, np.zeros(fft_size - len(low_cut_filter))] diff --git a/world/get_seeds_signals.py b/world/get_seeds_signals.py index f5f07e7..8afea6a 100644 --- a/world/get_seeds_signals.py +++ b/world/get_seeds_signals.py @@ -1,7 +1,7 @@ import numpy as np import numba from scipy.fftpack import fft, ifft, fftshift -from scipy.signal import hanning +from scipy.signal.windows import hann import random @@ -32,7 +32,7 @@ def get_seeds_signals(fs: int, fft_size: int=None, noise_length: int=None): spec[w > (frequency_interval * i)] = 1 pulse[:,i] = fftshift(ifft(np.r_[spec, spec[-2:0:-1]]).real) noise[:,i] = ifft(spec_n * fft(pulse[:,i], noise_length)).real - h = hanning(fft_size+2)[1:-1] + h = hann(fft_size+2)[1:-1] pulse[:,0] = pulse[:,0] - np.mean(pulse[:,0]) * h / np.mean(h) return {'pulse':pulse, 'noise':noise} diff --git a/world/harvest.py b/world/harvest.py index 5bdc294..859c1e9 100644 --- a/world/harvest.py +++ b/world/harvest.py @@ -46,7 +46,7 @@ def harvest(x: np.ndarray, fs: int, f0_floor: int=71, f0_ceil: int=800, frame_pe num_samples = int(1000 * len(x) / fs / frame_period + 1) temporal_positions = np.arange(0, num_samples) * frame_period / 1000 temporal_positions_sampe = np.minimum(len(smoothed_f0) - 1, round_matlab(temporal_positions * 1000)) - temporal_positions_sampe = np.array(temporal_positions_sampe, dtype=np.int) + temporal_positions_sampe = np.array(temporal_positions_sampe, dtype=np.int_) return { 'temporal_positions': temporal_positions, 'f0': smoothed_f0[temporal_positions_sampe], @@ -186,7 +186,7 @@ def GetRefinedF0(x: np.ndarray, fs: float, current_time: float, current_f0: floa diff = np.diff(main_window) diff_window[1:-1] = - (diff[1:] + diff[:-1]) / 2 - index = (np.maximum(1, np.minimum(len(x), index_raw)) - 1).astype(np.int) + index = (np.maximum(1, np.minimum(len(x), index_raw)) - 1).astype(np.int_) spectrum = fft(x[index] * main_window, fft_size) diff_spectrum = fft(x[index] * diff_window, fft_size) @@ -198,7 +198,7 @@ def GetRefinedF0(x: np.ndarray, fs: float, current_time: float, current_f0: floa number_of_harmonics = min(np.floor(fs / 2 / current_f0), 6) # with safe guard harmonic_index = np.arange(1, number_of_harmonics + 1) - index = round_matlab(current_f0 * fft_size / fs * harmonic_index).astype(np.int) + index = round_matlab(current_f0 * fft_size / fs * harmonic_index).astype(np.int_) instantaneous_frequency_list = instantaneous_frequency[index] amplitude_list = np.sqrt(power_spectrum[index]) refined_f0 = np.sum(amplitude_list * instantaneous_frequency_list) / np.sum(amplitude_list * harmonic_index) diff --git a/world/stonemask.py b/world/stonemask.py index d29dc2c..56a9d5f 100644 --- a/world/stonemask.py +++ b/world/stonemask.py @@ -46,7 +46,7 @@ def get_refined_f0(x, fs, current_time, current_f0): diff_window = -(np.diff(np.r_[0, main_window]) + np.diff(np.r_[main_window, 0])) / 2 index = np.maximum(1, np.minimum(len(x), index_raw )) - index = np.array(index, dtype=np.int) + index = np.array(index, dtype=np.int_) spectrum = np.fft.fft(x[index - 1] * main_window, fft_size) diff_spectrum = np.fft.fft(x[index - 1] * diff_window, fft_size) numerator_i = np.real(spectrum) * np.imag(diff_spectrum) - np.imag(spectrum) * np.real(diff_spectrum) @@ -57,7 +57,7 @@ def get_refined_f0(x, fs, current_time, current_f0): trim_index = np.array([1, 2]) index_list_trim = round_matlab(f0_initial * fft_size / fs * trim_index) + 1 - index_list_trim = np.array(index_list_trim, np.int) + index_list_trim = np.array(index_list_trim, np.int_) fixp_list = instantaneous_frequency[index_list_trim - 1] amp_list = np.sqrt(power_spectrum[index_list_trim - 1]) f0_initial = np.sum(amp_list * fixp_list) / np.sum(amp_list * trim_index) @@ -68,14 +68,14 @@ def get_refined_f0(x, fs, current_time, current_f0): trim_index = np.array([1, 2, 3, 4, 5, 6]) index_list_trim = round_matlab(f0_initial * fft_size / fs * trim_index) + 1 - index_list_trim = np.array(index_list_trim, np.int) + index_list_trim = np.array(index_list_trim, np.int_) fixp_list = instantaneous_frequency[index_list_trim - 1] amp_list = np.sqrt(power_spectrum[index_list_trim - 1]) refined_f0 = np.sum(amp_list * fixp_list) / np.sum(amp_list * trim_index) return refined_f0 -@numba.jit((numba.float64[:],), nopython=True, cache=True) +# @numba.jit((numba.float64[:],), nopython=True, cache=True) def round_matlab(x: np.ndarray) -> np.ndarray: ''' round function works as matlab round diff --git a/world/synthesis.py b/world/synthesis.py index 944f229..e9535ce 100644 --- a/world/synthesis.py +++ b/world/synthesis.py @@ -54,7 +54,7 @@ def synthesis(source_object, filter_object): amplitude_aperiodic = source_object['aperiodicity'] ** 2 amplitude_periodic = np.maximum(0.001, (1 - amplitude_aperiodic)) - dc_remover_base = signal.hanning(fft_size + 2)[1:-1] + dc_remover_base = signal.windows.hann(fft_size + 2)[1:-1] dc_remover_base = dc_remover_base / np.sum(dc_remover_base) coefficient = 2.0 * np.pi * fs / fft_size diff --git a/world/synthesisRequiem.py b/world/synthesisRequiem.py index ee249e4..d74c4f4 100644 --- a/world/synthesisRequiem.py +++ b/world/synthesisRequiem.py @@ -1,7 +1,7 @@ # 3rd-party imports import numpy as np from scipy.interpolate import interp1d -from scipy.signal import hanning +from scipy.signal.windows import hann from scipy.fftpack import fft, ifft import numba import matplotlib.pyplot as plt @@ -78,7 +78,7 @@ def get_waveform(excitation_signal, spectrogram, temporal_positions, f0, fs): frame_period_sample = int((temporal_positions[1] - temporal_positions[0]) * fs) win_len = frame_period_sample * 2 - 1 half_win_len = frame_period_sample - 1 - win = hanning(win_len+2)[1:-1] + win = hann(win_len+2)[1:-1] for i in range(2, len(f0)-1): origin = (i - 1) * frame_period_sample - half_win_len diff --git a/world/synthesis_a.py b/world/synthesis_a.py index cf0c5be..f6b095b 100644 --- a/world/synthesis_a.py +++ b/world/synthesis_a.py @@ -78,7 +78,7 @@ def synthesis(source_object, filter_object): # TODO: possible speed up via rfft? response = np.fft.fftshift(np.fft.ifft(np.exp(np.fft.ifft(tmp_complex_cepstrum))).real) - dc_remover = signal.hanning(len(response) + 2)[1:-1] + dc_remover = signal.windows.hann(len(response) + 2)[1:-1] dc_remover = dc_remover / np.sum(dc_remover) dc_remover = dc_remover * -np.sum(response) response += dc_remover