我正在使用googleapis包中的 Google Speech To Text API。但是我没有找到任何文档(对于 dart 和颤振)解释如何在发送 RecognizeRequest.fromJson 时使用应用程序资产文件夹中存在的本地音频文件作为音频数据。我想知道如何在代码中使用本地文件代替 _json 中的音频内容。提前致谢。
final httpClient = await clientViaServiceAccount(_credentials, _scopes);
try {
final speech2Text = SpeechApi(httpClient);
final _json = {
"config": {
"encoding": "FLAC",
"sampleRateHertz": 16000,
"languageCode": "en-US",
"enableWordTimeOffsets": false
},
"audio": {"uri": "gs://cloud-samples-tests/speech/brooklyn.flac"}
};
final _recognizeRequest = RecognizeRequest.fromJson(_json);
await speech2Text.speech.recognize(_recognizeRequest).then((response) {
for (var result in response.results) {
print(result.toJson());
}
});
} finally {
httpClient.close();
}
}