LoginSignup
0
0

Flutterプラグイン"speech_to_text"のBluetoothをオフに

Last updated at Posted at 2023-12-17

Flutterで端末の音声入力APIを利用できるspeech_to_text。権限周りの補足的記事です。

基本的な使い方については、既に多くの日本語記事がありますので、本記事では割愛します。

プラグインによるBluetoothアクセスをオフにする

speech_to_textはヘッドセットなどBluetooth接続される外部デバイスに対応しています。

2023年12月現在、最新バージョンではデフォルトの動作はBluetoothアクセスをユーザーに求める形となっています。

外部デバイスを利用する前提なら問題ありませんが、そうではない場合は余計な権限要求は避けたいところです。そこで、プラグインインスタンスを作成する際に次のとおりオプション設定を行うことで、Bluetoothをオフにすることができます。

import 'dart:io';
import 'package:speech_to_text/speech_to_text.dart';

final SpeechToText speechToText = SpeechToText();

//権限設定について環境に応じたオプションを指定
//Platformクラスはdart:io内に定義されています。
final options = [Platform.isIOS ? SpeechToText.iosNoBluetooth : SpeechToText.androidNoBluetooth];

//イニシャライズ時にオプションを指定
final available = await speechToText.initialize(options: options);
0
0
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
0
0