jamsch / expo-speech-recognition

Speech Recognition for React Native Expo projects
MIT License
128 stars 11 forks source link

Android verison is too old to trigger offline model download #8

Closed theprashant-one closed 2 months ago

theprashant-one commented 3 months ago

Hi, thank you for this awesome package!

my issue is that triggering model download failling (am on android 13)

sample code:

const data = ExpoSpeechRecognitionModule.getSpeechRecognitionServices()
      // ["com.google.android.as", "com.google.android.tts"]

const res = await ExpoSpeechRecognitionModule.getSupportedLocales({
        // Stil failling for - data[0], data[1]
        androidRecognitionServicePackage: "com.google.android.googlequicksearchbox", // also this
})

      /*
      {"installedLocales": ["en-US"], "locales": ["cmn-Hans-CN", "cmn-Hant-TW", "de-AT", "de-BE", "de-CH", "de-DE", "en-AU", "en-CA", "en-GB", "en-IE", "en-IN", "en-SG", "en-US", "es-ES", "es-US", "fr-BE", "fr-CA", "fr-CH", "fr-FR", "hi-IN", "id-ID", "it-CH", "it-IT", "ko-KR", "pl-PL", "pt-BR", "ru-RU", "th-TH", "tr-TR", "vi-VN"]}
      */

await ExpoSpeechRecognitionModule.androidTriggerOfflineModelDownload({
        locale: res.locales[6],
})

WhatsApp Image 2024-08-22 at 20 39 28_c20de576

jamsch commented 3 months ago

Hey @theprashant-one, good spotting! I hadn't yet implemented triggerModelDownload for Android 13 as it wasn't possible to listen for the status of the download in the SDK. As one temporary measure, the promise for androidTriggerOfflineModelDownload will have to instantly resolve, however you won't be able to know when the user has downloaded the model or if it failed.

jamsch commented 3 months ago

I've just published a release at v0.2.13 which should alllow Android 13 devices to open the model download dialog, however there's a few slight differences, as indicated here:

ExpoSpeechRecognitionModule.androidTriggerOfflineModelDownload({
    locale: props.locale,
  })
  .then((result) => {
    if (result.status === "opened_dialog") {
      // On Android 13, the status will be "opened_dialog" indicating that the model download dialog was opened.
      Alert.alert("Offline model download dialog opened.");
    } else if (result.status === "download_success") {
      // On Android 14+, the status will be "download_success" indicating that the model download was successful.
      Alert.alert("Offline model downloaded successfully!");
    }
  })
  .catch((err) => {
    Alert.alert("Failed to download offline model!", err.message);
  })
theprashant-one commented 3 months ago

hi @jamsch thanks for quick reponse. I will try this solution and let you know.

theprashant-one commented 3 months ago

One interesting thing I found is that I've downloaded several language packages, as you can see below, but the installed locales remain 'en-US'. Any guidance here?

{"installedLocales": ["en-US"], "locales": ["cmn-Hans-CN", "cmn-Hant-TW", "de-AT", "de-BE", "de-CH", "de-DE", "en-AU", "en-CA", "en-GB", "en-IE", "en-IN", "en-SG", "en-US", "es-ES", "es-US", "fr-BE", "fr-CA", "fr-CH", "fr-FR", "hi-IN", "id-ID", "it-CH", "it-IT", "ko-KR", "pl-PL", "pt-BR", "ru-RU", "th-TH", "tr-TR", "vi-VN"]}

this screenshot is from live transcribe settings menu (app from google)

WhatsApp Image 2024-08-23 at 18 01 59_b530aedb

jamsch commented 3 months ago

@theprashant-one The language models actually are installed under the Android System Intelligence app by default ("com.google.android.as"). On Samsung devices you can find the list of installed locales at: Settings -> Security and Privacy -> More privacy settings -> Android System Intelligence -> On-device speech recognition

jamsch commented 3 months ago

A bunch of menus to go through, I also got a bit mixed up because there were two Google apps that had options to download offline voice models too.

https://github.com/user-attachments/assets/f24396dc-1e3c-4f69-b952-ded19fedb4f5

theprashant-one commented 2 months ago

@jamsch, I can now see the downloaded locale. Thanks again!

jamsch commented 2 months ago

Sweet, closing this issue