ASR / scratch /test_pitch_debug.py
MihirRPatil's picture
deploy: CDAC ASR backend with pitch/stress fix and LLM feedback
88a679b
Raw
History Blame Contribute Delete
1.46 kB
import sys
import os
import numpy as np
import soundfile as sf
# Add CDAC_ASR to sys.path
sys.path.append("/home/mihir/Codes/CDAC_ASR")
from src.eval.ScoreCalcs import PronunciationScorer
def test_pitch():
# Convert mp3 to wav
mp3_path = "/home/mihir/Codes/CDAC_ASR/product/backend/cache/tts/cf673f7ee88828c9fb8f6acf2cb08403_normal.mp3"
wav_path = "/home/mihir/Codes/CDAC_ASR/scratch/test_debug.wav"
import subprocess
cmd = ["ffmpeg", "-y", "-i", mp3_path, "-ar", "16000", "-ac", "1", wav_path]
subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
speech, sr = sf.read(wav_path)
print(f"Loaded audio: shape={speech.shape}, sr={sr}")
scorer = PronunciationScorer()
# Dummy alignment and phoneme times
# Let's say we have 5 phonemes
n_phonemes = 5
duration = len(speech) / sr
step = duration / n_phonemes
times = [(i*step, (i+1)*step) for i in range(n_phonemes)]
aligned_pairs = [("a", "a")] * n_phonemes
# Extract contours
pred_contours = scorer._extract_pitch_contour(speech, sr, times)
print(f"Pred contours: {len(pred_contours)}")
for i, c in enumerate(pred_contours):
print(f" Phoneme {i}: len={len(c)}, mean={c.mean() if len(c) > 0 else 'empty'}")
res = scorer.pitch_score(speech, speech, sr, aligned_pairs, times, times)
print("Pitch score result:", res)
if __name__ == "__main__":
test_pitch()