1010#include < chrono>
1111#include < thread>
1212
13+ #include " SpeechRecognitionModelMapping.h"
1314#include " mozilla/Logging.h"
1415#include " mozilla/Mutex.h"
1516#include " mozilla/Preferences.h"
@@ -44,29 +45,9 @@ static LazyLogModule gSpeechRecognitionParentLog("SpeechRecognitionParent");
4445#define LOGE (fmt, ...) \
4546 MOZ_LOG_FMT (gSpeechRecognitionParentLog , LogLevel::Error, fmt, ##__VA_ARGS__)
4647
47- // Task name the model hub files speech recognition models under.
48- static constexpr auto kSpeechRecognitionTask = " speech-recognition" _ns;
49-
5048// Sample rate the Parakeet models operate at.
5149static constexpr int32_t PARAKEET_SAMPLE_RATE = 16000 ;
5250
53- SpeechRecognitionParent::ModelIdentifier
54- SpeechRecognitionParent::LanguagesToModelIdentifier (
55- const nsTArray<nsCString>&) {
56- // For now this ignores the requested languages and always returns a single
57- // hardcoded model. Per-language selection and generalization to more models
58- // land in a later patch in this stack.
59- // mudler/parakeet.cpp cache-aware streaming GGUF, hosted on the Mozilla
60- // model hub under asr-test/parakeet.
61- return {" asr-test/parakeet" _ns, " realtime_eou_120m-v1-q5_k.gguf" _ns,
62- " main" _ns};
63- }
64-
65- nsCString SpeechRecognitionParent::ModelIdentifier::ToString () const {
66- return nsFmtCString (" {}/{}/{}" , mModelName .get (), mFileName .get (),
67- mRevision .get ());
68- }
69-
7051void SpeechRecognitionParent::ResolveOrRejectInitOnIPCThread (
7152 InitResolver&& aResolver, bool aSuccess) {
7253 if (GetActorEventTarget ()->IsOnCurrentThread ()) {
@@ -133,14 +114,14 @@ mozilla::ipc::IPCResult SpeechRecognitionParent::RecvIsModelAvailable(
133114 " RecvIsModelAvailable requires at least one language" );
134115 }
135116
136- nsCString modelId = LanguagesToModelIdentifier (aLanguages). ToString ( );
117+ nsCString modelId = dom::LanguagesToSpeechModelId (aLanguages);
137118 LOGD (" {} languages: {} mapped to id={}" , __func__,
138119 fmt::join (aLanguages, " , " ), modelId.get ());
139120
140121 return RunHWInferenceBoolQuery (
141122 __func__,
142123 [modelId](hwinference::HWInferenceChild* aChild) {
143- return aChild->SendIsModelAvailable (nsCString ( kSpeechRecognitionTask ) ,
124+ return aChild->SendIsModelAvailable (dom:: kSpeechRecognitionTask ,
144125 modelId);
145126 },
146127 std::move (aResolver), mIsModelAvailableRequest );
@@ -152,7 +133,7 @@ mozilla::ipc::IPCResult SpeechRecognitionParent::RecvInstallModels(
152133 return IPC_FAIL (this , " RecvInstallModels requires at least one language" );
153134 }
154135
155- nsCString modelId = LanguagesToModelIdentifier (aLanguages). ToString ( );
136+ nsCString modelId = dom::LanguagesToSpeechModelId (aLanguages);
156137 LOGD (" {} languages: {} mapped to id={}" , __func__,
157138 fmt::join (aLanguages, " , " ), modelId.get ());
158139
@@ -162,7 +143,7 @@ mozilla::ipc::IPCResult SpeechRecognitionParent::RecvInstallModels(
162143 return RunHWInferenceBoolQuery (
163144 __func__,
164145 [modelId, contentId](hwinference::HWInferenceChild* aChild) {
165- return aChild->SendInstallModel (kSpeechRecognitionTask , modelId, 0 ,
146+ return aChild->SendInstallModel (dom:: kSpeechRecognitionTask , modelId, 0 ,
166147 contentId);
167148 },
168149 std::move (aResolver), mInstallModelRequest );
@@ -211,7 +192,7 @@ void SpeechRecognitionParent::RetrieveModel(InitResolver&& aResolver) {
211192 nsCString modelId;
212193 {
213194 MutexAutoLock lock (mLock );
214- modelId = LanguagesToModelIdentifier (nsTArray{mLanguage }). ToString ( );
195+ modelId = dom::LanguagesToSpeechModelId (nsTArray{mLanguage });
215196 }
216197
217198 LOGD (" {} Checking model is installed: id={}" , __func__, modelId.get ());
@@ -220,8 +201,7 @@ void SpeechRecognitionParent::RetrieveModel(InitResolver&& aResolver) {
220201 // permission doorhanger. start() requires the model to already be
221202 // installed, so check that before FetchModelFile() rather than letting
222203 // GetModelFile download it on demand.
223- hwInferenceChild
224- ->SendIsModelInstalled (nsCString (kSpeechRecognitionTask ), modelId)
204+ hwInferenceChild->SendIsModelInstalled (dom::kSpeechRecognitionTask , modelId)
225205 ->Then (GetCurrentSerialEventTarget (), __func__,
226206 [self = RefPtr{this }, aResolver = std::move (aResolver),
227207 modelId](hwinference::PHWInferenceChild::IsModelInstalledPromise::
@@ -256,8 +236,7 @@ void SpeechRecognitionParent::FetchModelFile(const nsCString& aModelId,
256236
257237 LOGD (" {} Requesting model: id={}" , __func__, aModelId.get ());
258238
259- hwInferenceChild
260- ->SendGetModelFile (nsCString (kSpeechRecognitionTask ), aModelId)
239+ hwInferenceChild->SendGetModelFile (dom::kSpeechRecognitionTask , aModelId)
261240 ->Then (
262241 GetCurrentSerialEventTarget (), __func__,
263242 [self = RefPtr{this }, aResolver = std::move (aResolver)](
0 commit comments