Flutter 使用Google';s语音到文本测试API

Flutter 使用Google';s语音到文本测试API,flutter,google-speech-api,google-speech-to-text-api,Flutter,Google Speech Api,Google Speech To Text Api,我正试图通过谷歌的API处理音频,并让人们使用这种语言。我不需要真实的成绩单。 我使用的是flutter,我看过了各种文档和网站上的问题 显然,似乎不支持检测语言功能。所以我看了一下,它似乎支持检测语言功能,并支持可选语言代码选项 然而,我能接触到的唯一例子是原始的v1api,显然有些函数与beta API有些不同 import 'package:flutter/material.dart'; import 'package:googleapis/speech/v1.dart'; import

我正试图通过谷歌的API处理音频,并让人们使用这种语言。我不需要真实的成绩单。 我使用的是flutter,我看过了各种文档和网站上的问题

显然,似乎不支持检测语言功能。所以我看了一下,它似乎支持检测语言功能,并支持可选语言代码选项

然而,我能接触到的唯一例子是原始的v1api,显然有些函数与beta API有些不同

import 'package:flutter/material.dart';
import 'package:googleapis/speech/v1.dart';
import 'package:googleapis_auth/auth_io.dart';

final _credentials = new ServiceAccountCredentials.fromJson(r'''
...
''');

const _SCOPES = const [SpeechApi.CloudPlatformScope];

void speechToText() {
  clientViaServiceAccount(_credentials, _SCOPES).then((http_client) {
    var speech = new SpeechApi(http_client);

final _json = {
  "audio": {
    "content":
        SAMPLECONTENT
  },
  "config": {
    "encoding": "LINEAR16",
    "sampleRateHertz": 16000,
    "languageCode": "fr-FR",
    "alternativeLanguageCodes": ["en-US", "ko-KR"],
  }
};
final _recognizeRequest = RecognizeRequest.fromJson(_json);
speech.speech.recognize(_recognizeRequest).then((response) {
    print(response.toJson());
    });
  });
}
下面是我使用原始API文档和StackOverflow的答案编写的代码。这不适用于beta API

import 'package:flutter/material.dart';
import 'package:googleapis/speech/v1.dart';
import 'package:googleapis_auth/auth_io.dart';

final _credentials = new ServiceAccountCredentials.fromJson(r'''
...
''');

const _SCOPES = const [SpeechApi.CloudPlatformScope];

void speechToText() {
  clientViaServiceAccount(_credentials, _SCOPES).then((http_client) {
    var speech = new SpeechApi(http_client);

final _json = {
  "audio": {
    "content":
        SAMPLECONTENT
  },
  "config": {
    "encoding": "LINEAR16",
    "sampleRateHertz": 16000,
    "languageCode": "fr-FR",
    "alternativeLanguageCodes": ["en-US", "ko-KR"],
  }
};
final _recognizeRequest = RecognizeRequest.fromJson(_json);
speech.speech.recognize(_recognizeRequest).then((response) {
    print(response.toJson());
    });
  });
}
问题如下:

  • 原始API不支持“alternativeLanguageCodes”的配置选项,因此似乎不支持检测语言

  • 测试版API的功能似乎与原始API不同,我只能找到原始API的示例

  • 我已经看了beta-API本身,并且花了最后一个小时看了同样的东西,但是仍然不知道如何让它们工作

  • 有人能帮我吗? 谢谢大家!