簡體   English   中英

Android studio 語音到文本離線模式不起作用

[英]Android studio Speech to text offline mode not working

我正在嘗試在我在 Android Studio 中開發的 Android 應用程序上離線工作時將語音轉換為文本。 這是我用來設置語音識別器的代碼。

    public void openSpeechMode(View view) {

        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());

        if(intent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(intent, 10);
        } else {
            Toast.makeText(context, "Your device does not support Speech Input.", Toast.LENGTH_LONG).show();
        }

    }

這在我在線時工作正常,但當我離線時它不起作用。 我讀到我需要確保在我的 Android 設備上遵循以下這些步驟......以確保我的設備具有在離線模式下工作所需的庫。

1)Go to Settings
2)Click on “Language and input”
3)Select Google voice typing
4)Select Offline speech recognition
5)Install desired language
6)Once the download was done, turn off the internet and test it !!

我按照這些步驟操作,並且在我的 android 設備上安裝了英語(英國)和英語(美國)。 但是當我離線時,語音到文本應用程序仍然不起作用。 當我單擊麥克風時,我收到消息說“網絡未連接”“再試一次”。

難道我做錯了什么? 任何人都可以提供幫助嗎? 謝謝

你可以試試這個來設置你的語言偏好。

String languagePref = "en-US";//as you have downloaded US english model
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, languagePref);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, languagePref); 
intent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, languagePref);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM