22import argparse
33import asyncio
44import logging
5+ import re
56from functools import partial
6- from pathlib import Path
7- from typing import Optional
87
8+ import faster_whisper
99from wyoming .info import AsrModel , AsrProgram , Attribution , Info
1010from wyoming .server import AsyncServer
1111
1212from . import __version__
13- from .const import WHISPER_LANGUAGES
14- from .download import FasterWhisperModel , download_model , find_model
15- from .faster_whisper import WhisperModel
1613from .handler import FasterWhisperEventHandler
1714
1815_LOGGER = logging .getLogger (__name__ )
@@ -24,7 +21,6 @@ async def main() -> None:
2421 parser .add_argument (
2522 "--model" ,
2623 required = True ,
27- choices = list (v .value for v in FasterWhisperModel ),
2824 help = "Name of faster-whisper model to use" ,
2925 )
3026 parser .add_argument ("--uri" , required = True , help = "unix:// or tcp://" )
@@ -78,17 +74,13 @@ async def main() -> None:
7874 )
7975 _LOGGER .debug (args )
8076
81- # Look for model
82- model = FasterWhisperModel (args .model )
83- model_dir : Optional [Path ] = None
84- for data_dir in args .data_dir :
85- model_dir = find_model (model , data_dir )
86- if model_dir is not None :
87- break
88-
89- if model_dir is None :
90- _LOGGER .info ("Downloading %s to %s" , model , args .download_dir )
91- model_dir = download_model (model , args .download_dir )
77+ model_name = args .model
78+ match = re .match (r"^(tiny|base|small|medium)[.-]int8$" , args .model )
79+ if match :
80+ # Original models re-uploaded to huggingface
81+ model_size = match .group (1 )
82+ model_name = f"{ model_size } -int8"
83+ args .model = f"rhasspy/faster-whisper-{ model_name } "
9284
9385 if args .language == "auto" :
9486 # Whisper does not understand "auto"
@@ -107,25 +99,26 @@ async def main() -> None:
10799 version = __version__ ,
108100 models = [
109101 AsrModel (
110- name = model . value ,
111- description = model . value ,
102+ name = model_name ,
103+ description = model_name ,
112104 attribution = Attribution (
113- name = "rhasspy " ,
114- url = "https://github.com/rhasspy/models/ " ,
105+ name = "Systran " ,
106+ url = "https://huggingface.co/Systran " ,
115107 ),
116108 installed = True ,
117- languages = WHISPER_LANGUAGES ,
118- version = "1.0" ,
109+ languages = faster_whisper . tokenizer . _LANGUAGE_CODES , # pylint: disable=protected-access
110+ version = faster_whisper . __version__ ,
119111 )
120112 ],
121113 )
122114 ],
123115 )
124116
125- # Load converted faster-whisper model
126- _LOGGER .debug ("Loading %s" , model_dir )
127- whisper_model = WhisperModel (
128- str (model_dir ),
117+ # Load model
118+ _LOGGER .debug ("Loading %s" , args .model )
119+ whisper_model = faster_whisper .WhisperModel (
120+ args .model ,
121+ download_root = args .download_dir ,
129122 device = args .device ,
130123 compute_type = args .compute_type ,
131124 )
0 commit comments