Skip to content

Commit 0f71367

Browse files
authored
fix(speech): enable location specific connections (#13757)
1 parent 78c09b5 commit 0f71367

File tree

6 files changed

+32
-5
lines changed

6 files changed

+32
-5
lines changed

generator/generator_config.textproto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3149,6 +3149,7 @@ service {
31493149
product_path: "google/cloud/speech/v2"
31503150
initial_copyright_year: "2022"
31513151
retryable_status_codes: ["kUnavailable"]
3152+
endpoint_location_style: LOCATION_DEPENDENT_COMPAT
31523153
}
31533154
31543155
# Sql

google/cloud/speech/doc/environment-variables.dox

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ environment variables are convenient when troubleshooting problems.
1414
`EndpointOption` (which defaults to "speech.googleapis.com")
1515
used by `MakeAdaptationConnection()`.
1616

17+
- `GOOGLE_CLOUD_CPP_SPEECH_ENDPOINT=...` overrides the
18+
`EndpointOption` (which defaults to "<location>-speech.googleapis.com")
19+
used by `MakeSpeechConnection()`.
20+
1721
- `GOOGLE_CLOUD_CPP_SPEECH_ENDPOINT=...` overrides the
1822
`EndpointOption` (which defaults to "speech.googleapis.com")
1923
used by `MakeSpeechConnection()`.

google/cloud/speech/v2/internal/speech_option_defaults.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "google/cloud/speech/v2/internal/speech_option_defaults.h"
2020
#include "google/cloud/speech/v2/speech_connection.h"
2121
#include "google/cloud/speech/v2/speech_options.h"
22+
#include "google/cloud/internal/absl_str_cat_quiet.h"
2223
#include "google/cloud/internal/populate_common_options.h"
2324
#include "google/cloud/internal/populate_grpc_options.h"
2425
#include <memory>
@@ -33,10 +34,12 @@ namespace {
3334
auto constexpr kBackoffScaling = 2.0;
3435
} // namespace
3536

36-
Options SpeechDefaultOptions(Options options) {
37+
Options SpeechDefaultOptions(std::string const& location, Options options) {
3738
options = internal::PopulateCommonOptions(
3839
std::move(options), "GOOGLE_CLOUD_CPP_SPEECH_ENDPOINT", "",
39-
"GOOGLE_CLOUD_CPP_SPEECH_AUTHORITY", "speech.googleapis.com");
40+
"GOOGLE_CLOUD_CPP_SPEECH_AUTHORITY",
41+
absl::StrCat(location, location.empty() ? "" : "-",
42+
"speech.googleapis.com"));
4043
options = internal::PopulateGrpcOptions(std::move(options));
4144
if (!options.has<speech_v2::SpeechRetryPolicyOption>()) {
4245
options.set<speech_v2::SpeechRetryPolicyOption>(

google/cloud/speech/v2/internal/speech_option_defaults.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121

2222
#include "google/cloud/options.h"
2323
#include "google/cloud/version.h"
24+
#include <string>
2425

2526
namespace google {
2627
namespace cloud {
2728
namespace speech_v2_internal {
2829
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
2930

30-
Options SpeechDefaultOptions(Options options);
31+
Options SpeechDefaultOptions(std::string const& location, Options options);
3132

3233
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
3334
} // namespace speech_v2_internal

google/cloud/speech/v2/speech_connection.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,13 @@ SpeechConnection::UndeletePhraseSet(
209209
Status(StatusCode::kUnimplemented, "not implemented"));
210210
}
211211

212-
std::shared_ptr<SpeechConnection> MakeSpeechConnection(Options options) {
212+
std::shared_ptr<SpeechConnection> MakeSpeechConnection(
213+
std::string const& location, Options options) {
213214
internal::CheckExpectedOptions<CommonOptionList, GrpcOptionList,
214215
UnifiedCredentialsOptionList,
215216
SpeechPolicyOptionList>(options, __func__);
216-
options = speech_v2_internal::SpeechDefaultOptions(std::move(options));
217+
options =
218+
speech_v2_internal::SpeechDefaultOptions(location, std::move(options));
217219
auto background = internal::MakeBackgroundThreadsFactory(options)();
218220
auto auth = internal::CreateAuthenticationStrategy(background->cq(), options);
219221
auto stub =
@@ -223,6 +225,10 @@ std::shared_ptr<SpeechConnection> MakeSpeechConnection(Options options) {
223225
std::move(background), std::move(stub), std::move(options)));
224226
}
225227

228+
std::shared_ptr<SpeechConnection> MakeSpeechConnection(Options options) {
229+
return MakeSpeechConnection(std::string{}, std::move(options));
230+
}
231+
226232
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
227233
} // namespace speech_v2
228234
} // namespace cloud

google/cloud/speech/v2/speech_connection.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <google/cloud/speech/v2/cloud_speech.pb.h>
3434
#include <google/longrunning/operations.grpc.pb.h>
3535
#include <memory>
36+
#include <string>
3637

3738
namespace google {
3839
namespace cloud {
@@ -285,9 +286,20 @@ class SpeechConnection {
285286
* @note Unexpected options will be ignored. To log unexpected options instead,
286287
* set `GOOGLE_CLOUD_CPP_ENABLE_CLOG=yes` in the environment.
287288
*
289+
* @param location Sets the prefix for the default `EndpointOption` value.
288290
* @param options (optional) Configure the `SpeechConnection` created by
289291
* this function.
290292
*/
293+
std::shared_ptr<SpeechConnection> MakeSpeechConnection(
294+
std::string const& location, Options options = {});
295+
296+
/**
297+
* A backwards-compatible version of the previous factory function. Unless
298+
* the service also offers a global endpoint, the default value of the
299+
* `EndpointOption` may be useless, in which case it must be overridden.
300+
*
301+
* @deprecated Please use the `location` overload instead.
302+
*/
291303
std::shared_ptr<SpeechConnection> MakeSpeechConnection(Options options = {});
292304

293305
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END

0 commit comments

Comments
 (0)