3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

備忘録 flutter開発で音声入力したいけど speech_to_text がうまく作動しない。

Posted at

課題

下記リファレンスを参考にspeech_to_text でマイクから音声を拾って文章に文字起こしをしたいがうまく作動しない。

下記のようなコードを組んで問題点を調査したところ"The user has denied the use of speech recognition."が呼ばれた。どうやらspeech_to_textをインスタンス化するところで失敗している模様。


    var hasSpeech = await speech.initialize(
        onError: errorListener,
        onStatus: statusListener,
        debugLogging: true,
        finalTimeout: Duration(milliseconds: 0));

    if (hasSpeech) {
      _localeNames = await speech.locales();
      print('_localeNames');
      print(_localeNames);

      var systemLocale = await speech.systemLocale();
      _currentLocaleId = systemLocale.localeId;

      speech.listen( onResult: resultListener );
    } else {
      print("The user has denied the use of speech recognition.");
    }

#解決策
app/src/main の Android Manifest に uses-permissionのタグ二つとqueriesを追加する。
これによってアプリ起動時にマイクへのアクセスが求められる様になり、音声入力が可能となる。


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.higuuu.job_interview">
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.INTERNET" />
    <queries>
        <intent>
            <action android:name="android.speech.RecognitionService" />
        </intent>
    </queries>


3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?