パッケージ、リポジトリ、アプリカテゴリを検索

google_speech のカバー
パッケージ詳細v5.3.0

google_speech

Google Cloud GRPC 音声認識テキスト変換API用のFlutterプラグイン。

AndroidiOSmacOSWindowsLinux
30日間ダウンロード
1790
いいね数
144
Pub ポイント
120

パッケージをインストール

flutter pub add google_speech

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

google_speech パッケージは、Flutterアプリケーションでリアルタイムの音声認識を可能にするGoogle Cloud GRPC 音声からテキストへのAPIとの統合を可能にするFlutterプラグインです。ストリーミング音声入力をサポートし、複数のプラットフォームで正確な音声認識を提供します。音声機能を備えたアプリを開発する開発者向けに設計されており、最小限のセットアップでGoogleの強力なASR(自動音声認識)機能に簡単にアクセスできます。このプラグインはGoogle Cloud認証情報を使用して認証を処理し、継続的なトランスクリプションのためにイベント駆動型の応答を提供します。音声アシスタント、字下げツール、アクセシビリティ機能に最適です。

用途

  • 音声アシスタント
  • リアルタイム音声認識
  • 音声入力アプリ
  • アクセシビリティツール
  • オーディオログ

主な機能

  • リアルタイムストリーミング
  • Google Cloud 統合
  • クロスプラットフォーム対応
  • イベント駆動型API
  • Google Cloud を通じた認証

適している対象

  • 音声対応アプリを開発する開発者
  • 高精度の音声認識を必要とするアプリ
  • Google Cloud サービスを使用するプロジェクト
  • モバイルおよびデスクトップ音声アプリケーション

注意事項

  • Google Cloud プロジェクトと API キーが必要です
  • 使用に対して請求が適用されます
  • ネットワーク接続が必要です
  • 低帯域幅接続における高い遅延
  • ネイティブ依存関係のプラットフォーム固有のセットアップ

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

Google Speech

This package allows the use of Google Speech Api with grpc as a pure Dart implementation. With the support of grpc it is also possible to use the streaming transcription of the Google Speech Api with this package.

Demo recognize

Demo with recognize

Demo Streaming

Demo with streaming

Before we get started

To use the Google Speech Api it is first of all important to create a Google Cloud account and activate the Speech Api. The best way to do this is to follow the first point of this documentation.

After you have created a service account and downloaded the Json file with the necessary access data, you can start using this package.

At this time this package only supports authentication via service account. It is therefore necessary to create a service account and have the necessary Json data ready.

Getting Started

Authentication

As of version 3.0.0 there are now 3 different ways to authenticate. In addition to the old way viaServiceAccount, there is now also the possibility to authenticate via token or ThirdPartyAuthenticator.

Authentication via ThirdParty Authenticator [> Version 3.0.0]
   final speechToText = SpeechToText.viaThirdPartyAuthenticator(
      ThirdPartyAuthenticator(
        obtainCredentialsFromThirdParty: () async {
          // request api to get token
          final json = await requestCredentialFromMyApi();
          return AccessCredentials.fromJson(json);
          },
      ),
    );
Authentication via Token [> Version 3.0.0]

Creates a SpeechToText interface using a token. You are responsible for updating the token when it expires.

    final speechToText = SpeechToText.viaToken(
    'Bearer',
    '<token-here>',
    );
Authentication via a service account

There are two ways to log in using a service account. Option number one is the direct transfer of the Json file. Make sure that the file really exists in the path you passed and that the file has a .json extension.

    import 'package:google_speech/speech_client_authenticator.dart';
    
    final serviceAccount = ServiceAccount.fromFile(File('PATH_TO_FILE'));

    final speechToText = SpeechToText.viaServiceAccount(serviceAccount);

Option number two is to pass the Json data directly as a string. This could be used for example to load the data from an external service first and not have to keep it directly in the app.

    final serviceAccount = ServiceAccount.fromString(r'''{YOUR_JSON_STRING}''');
    
    /// OR load the data from assets
    
    final serviceAccount = ServiceAccount.fromString(
        '${(await rootBundle.loadString('assets/test_service_account.json'))}');

    final speechToText = SpeechToText.viaServiceAccount(serviceAccount);

After you have successfully connected the ServiceAccount, you can already start using the Api.

Transcribing a file using recognize
Define a RecognitionConfig
    final config = RecognitionConfig(
                         encoding: AudioEncoding.LINEAR16,
                         model: RecognitionModel.basic,
                         enableAutomaticPunctuation: true,
                         sampleRateHertz: 16000,
                         languageCode: 'en-US');
Get the contents of the audio file
     Future<List<int>> _getAudioContent(String name) async {
       final directory = await getApplicationDocumentsDirectory();
       final path = directory.path + '/$name';
       return File(path).readAsBytesSync().toList();
     }
    
    final audio = await _getAudioContent('test.wav');
And finally send the request
    final response = await speechToText.recognize(config, audio);
Transcribing a file using streamRecognize
Define a StreamingRecognitionConfig
    final streamingConfig = StreamingRecognitionConfig(config: config, interimResults: true);
Get the contents of the audio file as stream || or get an audio stream directly from a microphone input
     Future<Stream<List<int>>> _getAudioStream(String name) async {
       final directory = await getApplicationDocumentsDirectory();
       final path = directory.path + '/$name';
       return File(path).openRead();
     }
    
    final audio = await _getAudioStream('test.wav');
And finally send the request
    final responseStream = speechToText.streamingRecognize(streamingConfig, audio);
    responseStream.listen((data) {
        // listen for response 
    });

More information can be found in the official Google Cloud Speech documentation.

Getting empty response (Issue #25)

If it happens that google_speech returns an empty response, then this error is probably due to the recorded audio file.

You can find more information here https://cloud.google.com/speech-to-text/docs/troubleshooting#returns_an_empty_response

Use Google Speech Beta

Since version 1.1.0 google_speech also supports the use of features available in the Google Speech Beta Api. For this you just have to use SpeechToTextBeta instead of SpeechToText.

Use Google Speech Version 2

Since version 4.0.0 google_speech also supports the use of features available in the Google Speech V2. For this you just have to use SpeechToTextV2 instead of SpeechToText. An Example could be found in audio_file_example_v2

Endless stream support

Since version 5.0.0 google_speech also supports endless stream. For this you just have to use EndlessStreamingService instead of SpeechToText.

    final serviceAccount = ServiceAccount.fromString(r'''{YOUR_JSON_STRING}''');
    
    /// OR load the data from assets
    
    final serviceAccount = ServiceAccount.fromString(
        '${(await rootBundle.loadString('assets/test_service_account.json'))}');

    final speechToText = EndlessStreamingService.viaServiceAccount(serviceAccount);

    final responseStream = speechToText.endlessStream;
    
    speechToText.endlessStreamingRecognize(
        StreamingRecognitionConfig(config: config, interimResults: true),
        _audioStream!);
    
    responseStream.listen((data) {...});

カテゴリー

依存関係

依存関係一覧 8 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。