Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a minimalistic setup.py #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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',
]
)
2 changes: 1 addition & 1 deletion world/cheaptrick.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion world/d4c.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 + \
Expand Down
2 changes: 1 addition & 1 deletion world/d4cRequiem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 + \
Expand Down
2 changes: 1 addition & 1 deletion world/dio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down
4 changes: 2 additions & 2 deletions world/get_seeds_signals.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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}
Expand Down
6 changes: 3 additions & 3 deletions world/harvest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions world/stonemask.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion world/synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions world/synthesisRequiem.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion world/synthesis_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down