Downloads · 30 days
0
hidude562/prosody-predictor
prosody-predictor is a machine learning model from hidude562. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
A small (682K param) convolutional model that predicts pitch (F0) and volume (RMS) contours from text at 100ms resolution.
Downloads · 30 days
0
Access
Public
Updated Mar 19, 2026
Repo size
20.7 MB
Likes
0
Public
Click a slice to open those files.
.pt20.7 MB · 100%
From the Hugging Face model README
A small (682K param) convolutional model that predicts pitch (F0) and volume (RMS) contours from text at 100ms resolution.
Text -> CharEncoder (4x Conv1d) -> DurationPredictor (2x Conv1d, detached)
-> LengthRegulator (repeat by durations)
-> FrameDecoder (3x Conv1d) -> [F0, RMS]
import torch
from model_prosody import ProsodyPredictor
from infer_prosody import predict_prosody
ckpt = torch.load("final_model.pt", map_location="cpu", weights_only=False)
model = ProsodyPredictor(vocab_size=ckpt["vocab_size"], d_model=128, dropout=0.0)
model.load_state_dict(ckpt["model"])
model.eval()
result = predict_prosody("Hello, I am Kobi AI", model, ckpt["norm_stats"])
# result["f0_hz"] - pitch in Hz per 100ms frame
# result["rms"] - volume per 100ms frame
# result["duration_s"] - total duration in seconds
import numpy as np
import soundfile as sf
from scipy.interpolate import CubicSpline
f0 = result["f0_hz"]
rms = result["rms"]
sr = 24000
frame_dur = 0.1
n_frames = len(f0)
total_samples = int(n_frames * frame_dur * sr)
# Smooth interpolation between frames
frame_times = (np.arange(n_frames) + 0.5) * frame_dur
sample_times = np.arange(total_samples) / sr
f0_smooth = np.clip(CubicSpline(frame_times, f0, bc_type='clamped')(sample_times), 50, 300)
rms_smooth = np.clip(CubicSpline(frame_times, rms, bc_type='clamped')(sample_times), 0, None)
# Generate with continuous phase
phase = np.cumsum(2 * np.pi * f0_smooth / sr)
audio = (rms_smooth * np.sin(phase)).astype(np.float32)
audio = audio / (np.abs(audio).max() + 1e-8) * 0.8
sf.write("output.wav", audio, sr)
| File | Description |
|---|---|
final_model.pt | Fully trained model (200 epochs, 8000 steps) |
best_model.pt | Best validation checkpoint (val loss 1.078) |
model_prosody.py | Model definition (ProsodyPredictor) |
infer_prosody.py | Inference helper (predict_prosody()) |
extract_features.py | Feature extraction from WAV + text (vocab, tokenizer) |
MSE(pitch, voiced only) + MSE(volume, all frames) + 0.1 * MSE(log duration)