Skip to content

Repository files navigation

Japanese Pitch Accent Analyzer (Sandbox)

Japanese Pitch Accent Analyzer is a specialized research and study tool designed to help learners master Japanese prosody. It allows users to compare their speech against reference audio (e.g., anime clips) using AI-driven forced alignment and pitch normalization.

The project focuses on Mora-synchronous comparison, moving beyond raw waveform matching to provide linguistically meaningful feedback.

UI screenshot

🌟 Key Functionalities

1. AI-Powered Audio Preprocessing

  • Vocal Extraction (UVR): Uses audio-separator (Ultimate Vocal Remover) to isolate voices from background music/noise in anime clips.
  • Voice Activity Detection (VAD): Employs Silero VAD to trim silences, ensuring the analyzer focuses only on spoken segments.

2. Linguistic Alignment & Prediction

  • Forced Alignment: Utilizes Wav2Vec2 to map Hiragana/Kanji transcripts to exact timestamps in the audio.
  • Theoretical Prediction: Integrates pyopenjtalk to generate the "dictionary correct" pitch accent pattern (High/Low) for the input text. It uses the Marine predictor.

3. Pitch Normalization & Visualization

  • Acoustic Scaling: Converts raw Hertz (Hz) to Semitones relative to the speaker's mean. This allows a deep-voiced male to be compared directly with a high-pitched female character.
  • Mora-Anchored Plotting: Instead of simple time-warping, pitch is aggregated per Mora (syllable), providing an "OJAD-style" visual graph.

📦 Installation

To install this project use the following commands.

# Clone the repository
git clone <your-repo-url>
cd pitch_accent

# Create environment and install dependencies
pip install -e .

The recommended models are:

They should be included in the .env file with the path to directory of the checkpoints like:

ALIGNER_MODEL_PATH="checkpoints/wav2vec/japanese-wav2vec2-large-rs35kh"
VOCALS_REMOVER_PATH="checkpoints/vocals"

🚀 Usage (Standalone Tester)

The standalone app is designed for rapid iteration of the pitch accent analysis logic.

python src/pitch-accent-analyzer/app.py
  1. Upload Reference: Provide the anime audio segment.
  2. Input Transcript: Enter the Hiragana/Kanji (e.g., わたしはげんきです).
  3. Record: Speak the same sentence into the microphone.
  4. Analyze: View the synchronized pitch contours.

🛠️ Architectural Decisions & Justifications

Mora Synchronization

The pitch is aligned to Moras instead of using the time as X-axis.

2. Semitone Normalization

The pitch is normalized using semitones with the formula12 * log2(f / mean_f). Normalizing to semitones relative to the mean removes the "Gender/Age Gap" while preserving the "Intonation Shape."

3. UVR Integration

Fundamental Frequency (F0) estimation (Parselmouth/Praat) fails in the presence of harmonic noise (music). Without UVR, the anime pitch curve would be jagged and incorrect.


🔬 Component Overview

AudioLoader

Handles unified ingestion. It converts non-WAV formats to WAV on-the-fly, as Parselmouth is strict about headers.

JapaneseForcedAligner

The "brain" of the temporal alignment.

  • align(audio, text): Generates character-level timestamps.
  • group_into_moras(spans): Merges small kana (e.g., ょ) into their parent mora for correct Japanese prosody analysis.

PitchVisualizer

Uses matplotlib-fontja to ensure Japanese characters render correctly across all Operating Systems without manual font configuration.


🔒 Privacy

This tool is strictly for personal educational use. It does not facilitate the distribution of copyrighted content. All audio processing is performed locally; no data is uploaded to external servers.

References

Author

aipracticecafe aipracticecafe-codeberg

License

This project is licensed under the MIT. Details are in the LICENSE file.

About

Japanese pitch accent analyzer with mora timestamping and pitch visualization

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages