Flutter 使用Google';s语音到文本测试API
我正试图通过谷歌的API处理音频,并让人们使用这种语言。我不需要真实的成绩单。 我使用的是flutter,我看过了各种文档和网站上的问题 显然,似乎不支持检测语言功能。所以我看了一下,它似乎支持检测语言功能,并支持可选语言代码选项 然而,我能接触到的唯一例子是原始的v1api,显然有些函数与beta 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
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());
});
});
}
问题如下: