Update:
Here's a working sample:
https://gist.github.com/DazWilkin/34d628b998b4266be818ffb3efd688aa
You need only plug the values of a service account key.json and should receive:
{
alternatives: [{
confidence: 0.9835046,
transcript: how old is the Brooklyn Bridge
}]
}
It is poorly documented :-(
I'm familiar with Google API development but unfamiliar with Dart and with the Google Speech-to-Text API so, apologies in advance.
See:
https://github.com/dart-lang/googleapis/tree/master/generated/googleapis
There are 2 flavors of Google SDK|library, the more common (API Client Libraries) and the new (Cloud [!] Client Libraries). IIUC, for Dart for Speech you're going to use the API Client Library and this doesn't use gRPC.
I'm going to tweak the sample by gut, so bear with me:
import 'package:googleapis/speech/v1.dart';
import 'package:googleapis_auth/auth_io.dart';
final _credentials = new ServiceAccountCredentials.fromJson(r'''
{
"private_key_id": ...,
"private_key": ...,
"client_email": ...,
"client_id": ...,
"type": "service_account"
}
''');
const _SCOPES = const [SpeechApi.CloudPlatformScope];
void main() {
clientViaServiceAccount(_credentials, _SCOPES).then((http_client) {
var speech = new SpeechApi(http_client);
speech...
});
}
This requires the creation of a service account with appropriate permissions and a (JSON) key generated for it. Generally, the key file is loaded by the code but, in this example, it's provided as a string literal. The key will provide the content for fromJson
. You ought (!) to be able to use Application Default Credentials for testing (easier) see the link below.
Somehow (!) the Dart API will include a method|function that makes this underlying REST call. The call expects some configuration and the audio:
https://cloud.google.com/speech-to-text/docs/reference/rest/v1/speech/recognize
I suspect it's this recognize and it expects a RecognizeRequest
Sorry I can't be of more help.
If you do get it working, please consider publishing the same so others may benefit.
NB