felixjunghans / google_speech

Flutter google spech
MIT License
68 stars 41 forks source link

Support configuration of service region #53

Closed simonbrandhof closed 9 months ago

simonbrandhof commented 9 months ago

The Google Speech API provides the capability to select the service region when sending requests (US or Europe). That can be important for the compliance with local regulatory requirements, and probably for better performances for nearby users.

Currently the global endpoint speech.googleapis.com is hardcoded in the SpeechToText class and can't be changed. It would be great to add the support for its configuration, for example by using an enum:

SpeechToText.viaServiceAccount(serviceAccount, region: Region.europe);
felixjunghans commented 9 months ago

Hey @simonbrandhof,

Thank you for your feedback. I have just released version 5.1.0. It is now possible to use regional endpoints with the optional parameter 'cloudSpeechEndpoint'. I hope this helps you.

SpeechToText.viaServiceAccount(serviceAccount, cloudSpeechEndpoint: 'https://eu-speech.googleapis.com');

EDIT - Thanks for the hint. The correct code example would be:

SpeechToText.viaServiceAccount(serviceAccount, cloudSpeechEndpoint: 'eu-speech.googleapis.com');

simonbrandhof commented 9 months ago

Excellent, kudos to you 👍

simonbrandhof commented 9 months ago

Note that the parameter cloudSpeechEndpoint is the host, but not the URL. The correct example is:

SpeechToText.viaServiceAccount(serviceAccount, cloudSpeechEndpoint: 'eu-speech.googleapis.com');
felixjunghans commented 9 months ago

Ahh, you're right. Thanks for the correction.