1919import time
2020import wave
2121from dataclasses import dataclass
22- from pathlib import Path
2322from typing import Protocol
2423
2524import aiohttp
2625import soundfile as sf
2726import torch
28- import transformers
2927from jiwer import process_words
3028from tqdm import tqdm
3129
@@ -80,57 +78,17 @@ class SampleOutput:
8078
8179@functools .lru_cache (maxsize = 1 )
8280def _get_en_normalizer ():
83- """Lazy-load the English text normalizer.
84-
85- Tries whisper_normalizer (standalone pip package) first, then openai-whisper,
86- then the transformers built-in normalizer.
87-
88- note (Chenyang): The three fallbacks exist because our deployments don't always
89- have whisper_normalizer installed, whisper's own normalizer lives under a
90- different path depending on the release, and on minimal CI images we rely on
91- the transformers copy bundled with the library. Keeping all three paths lets
92- the WER numbers stay stable across environments (the official seed-tts-eval
93- reference uses whisper_normalizer, so we prefer it when available).
94- """
95- try :
96- from whisper_normalizer .english import EnglishTextNormalizer
97-
98- normalizer = EnglishTextNormalizer ()
99- logger .info ("Using whisper_normalizer.english.EnglishTextNormalizer" )
100- return normalizer
101- except ImportError :
102- logger .debug ("whisper_normalizer.english.EnglishTextNormalizer failed" )
103-
81+ """Lazy-load the required English WER normalizer from openai-whisper."""
10482 try :
10583 from whisper .normalizers import EnglishTextNormalizer
84+ except ImportError as exc :
85+ raise RuntimeError (
86+ "English WER requires openai-whisper "
87+ "(whisper.normalizers.EnglishTextNormalizer). "
88+ "Install pinned deps with `uv pip install -e .`."
89+ ) from exc
10690
107- normalizer = EnglishTextNormalizer ()
108- logger .info ("Using whisper.normalizers.EnglishTextNormalizer" )
109- return normalizer
110- except ImportError :
111- logger .debug ("whisper.normalizers.EnglishTextNormalizer failed" )
112-
113- try :
114- from transformers .models .whisper .english_normalizer import EnglishTextNormalizer
115-
116- json_path = (
117- Path (transformers .__file__ ).parent / "models" / "whisper" / "english.json"
118- )
119- with open (json_path ) as f :
120- english_spelling_mapping = json .load (f )
121-
122- normalizer = EnglishTextNormalizer (english_spelling_mapping )
123- logger .info (
124- "Using transformers.models.whisper.english_normalizer.EnglishTextNormalizer"
125- )
126- return normalizer
127- except (ImportError , FileNotFoundError ) as exc :
128- logger .debug (f"transformers EnglishTextNormalizer failed: { exc } " )
129-
130- logger .warning (
131- "EnglishTextNormalizer not found; falling back to punctuation-strip normalizer."
132- )
133- return None
91+ return EnglishTextNormalizer ()
13492
13593
13694def normalize_text (text : str , lang : str ) -> str :
@@ -147,15 +105,7 @@ def normalize_text(text: str, lang: str) -> str:
147105 return text
148106
149107 normalizer = _get_en_normalizer ()
150- if normalizer is not None :
151- return normalizer (text )
152-
153- for ch in string .punctuation :
154- if ch == "'" :
155- continue
156- text = text .replace (ch , "" )
157- text = text .replace (" " , " " ).strip ().lower ()
158- return text
108+ return normalizer (text )
159109
160110
161111def load_asr_model (lang : str , device : str , generation_mode : str | None = None ):
0 commit comments