utils#
- diffsptk.get_alpha(sr: int, mode: str = 'hts', n_freq: int = 10, n_alpha: int = 100) float [source]#
Compute an appropriate frequency warping factor given the sample rate.
- Parameters:
- srint >= 1
The sample rate in Hz.
- mode[‘hts’, ‘auto’]
‘hts’ returns a traditional alpha used in HTS. ‘auto’ computes an appropriate alpha in the L2 sense.
- n_freqint >= 2
The number of sample points in the frequency domain.
- n_alphaint >= 1
The number of sample points to search alpha.
- Returns:
- outfloat in [0, 1)
The frequency warping factor, \(\alpha\).
Examples
>>> _, sr = diffsptk.read("assets/data.wav") >>> alpha = diffsptk.get_alpha(sr) >>> alpha 0.42
- diffsptk.read(filename: str, device: device | None = None, dtype: dtype | None = None, **kwargs) tuple[Tensor, int] [source]#
Read a waveform from the given file.
- Parameters:
- filenamestr
The path of the wav file.
- devicetorch.device or None
The device of the returned tensor.
- dtypetorch.dtype or None
The data type of the returned tensor.
- **kwargsadditional keyword arguments
Additional arguments passed to soundfile.read.
- Returns:
- xTensor
The waveform.
- srint
The sample rate in Hz.
Examples
>>> x, sr = diffsptk.read("assets/data.wav") >>> x tensor([ 0.0002, 0.0004, 0.0006, ..., 0.0006, -0.0006, -0.0007]) >>> sr 16000
- diffsptk.write(filename: str, x: Tensor, sr: int, **kwargs) None [source]#
Write the given waveform to a file.
- Parameters:
- filenamestr
The path of the wav file.
- xTensor
The waveform.
- srint
The sample rate in Hz.
- **kwargsadditional keyword arguments
Additional arguments passed to soundfile.write.
Examples
>>> x, sr = diffsptk.read("assets/data.wav") >>> diffsptk.write("out.wav", x, sr)
- diffsptk.tau#
The value of \(2\pi\).
- diffsptk.two_pi#
The value of \(2\pi\).