PyWorld: Python Wrapper for WORLD Vocoder

0.3.5 · active · verified Thu Apr 16

PyWorld is a Python wrapper for the WORLD vocoder, a highly efficient and high-quality speech analysis, manipulation, and synthesis system. It allows users to extract fundamental frequency (f0), harmonic spectral envelope (sp), and aperiodic spectral envelope (ap) from speech, and subsequently synthesize speech from these parameters. The library is currently at version 0.3.5 and is actively maintained, though major releases have been infrequent. [1, 7, 9, 11]

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to simulate a basic audio waveform and then use `pyworld.wav2world` to extract the fundamental frequency (f0), spectral envelope (sp), and aperiodicity (ap). It also shows how to synthesize audio back from these features. [1, 7, 9]

import numpy as np
import pyworld as pw

# Simulate a mono audio waveform (e.g., 2 seconds at 44.1 kHz)
fs = 44100 # Sampling frequency
t = np.arange(0, 2.0, 1.0/fs) # Time vector
f0_val = 200 # Hz
x = 0.5 * np.sin(2 * np.pi * f0_val * t).astype(np.float64)

# Ensure the waveform is float64 as expected by pyworld
# Extract WORLD features
f0, sp, ap = pw.wav2world(x, fs)

print(f"Extracted f0 shape: {f0.shape}")
print(f"Extracted spectral envelope shape: {sp.shape}")
print(f"Extracted aperiodicity shape: {ap.shape}")

# Synthesize speech back (optional, requires additional components like 'y')
y_synthesized = pw.synthesize(f0, sp, ap, fs)
print(f"Synthesized audio shape: {y_synthesized.shape}")

view raw JSON →