From 51375d3dade94a6286a5bbf102ecb40815009bae Mon Sep 17 00:00:00 2001 From: Scott Hart Date: Fri, 8 Mar 2024 15:25:43 -0500 Subject: [PATCH] regenerate speech v2 code --- google/cloud/speech/doc/environment-variables.dox | 4 ++++ .../speech/v2/internal/speech_option_defaults.cc | 7 +++++-- .../speech/v2/internal/speech_option_defaults.h | 3 ++- google/cloud/speech/v2/speech_connection.cc | 10 ++++++++-- google/cloud/speech/v2/speech_connection.h | 12 ++++++++++++ 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/google/cloud/speech/doc/environment-variables.dox b/google/cloud/speech/doc/environment-variables.dox index bbd3616d6220..7ec841feec8c 100644 --- a/google/cloud/speech/doc/environment-variables.dox +++ b/google/cloud/speech/doc/environment-variables.dox @@ -14,6 +14,10 @@ environment variables are convenient when troubleshooting problems. `EndpointOption` (which defaults to "speech.googleapis.com") used by `MakeAdaptationConnection()`. +- `GOOGLE_CLOUD_CPP_SPEECH_ENDPOINT=...` overrides the + `EndpointOption` (which defaults to "-speech.googleapis.com") + used by `MakeSpeechConnection()`. + - `GOOGLE_CLOUD_CPP_SPEECH_ENDPOINT=...` overrides the `EndpointOption` (which defaults to "speech.googleapis.com") used by `MakeSpeechConnection()`. diff --git a/google/cloud/speech/v2/internal/speech_option_defaults.cc b/google/cloud/speech/v2/internal/speech_option_defaults.cc index 3a439a4b347f..3bcf9bcc30ca 100644 --- a/google/cloud/speech/v2/internal/speech_option_defaults.cc +++ b/google/cloud/speech/v2/internal/speech_option_defaults.cc @@ -19,6 +19,7 @@ #include "google/cloud/speech/v2/internal/speech_option_defaults.h" #include "google/cloud/speech/v2/speech_connection.h" #include "google/cloud/speech/v2/speech_options.h" +#include "google/cloud/internal/absl_str_cat_quiet.h" #include "google/cloud/internal/populate_common_options.h" #include "google/cloud/internal/populate_grpc_options.h" #include @@ -33,10 +34,12 @@ namespace { auto constexpr kBackoffScaling = 2.0; } // namespace -Options SpeechDefaultOptions(Options options) { +Options SpeechDefaultOptions(std::string const& location, Options options) { options = internal::PopulateCommonOptions( std::move(options), "GOOGLE_CLOUD_CPP_SPEECH_ENDPOINT", "", - "GOOGLE_CLOUD_CPP_SPEECH_AUTHORITY", "speech.googleapis.com"); + "GOOGLE_CLOUD_CPP_SPEECH_AUTHORITY", + absl::StrCat(location, location.empty() ? "" : "-", + "speech.googleapis.com")); options = internal::PopulateGrpcOptions(std::move(options)); if (!options.has()) { options.set( diff --git a/google/cloud/speech/v2/internal/speech_option_defaults.h b/google/cloud/speech/v2/internal/speech_option_defaults.h index cd341dc7ddb6..6c7e3d5660f6 100644 --- a/google/cloud/speech/v2/internal/speech_option_defaults.h +++ b/google/cloud/speech/v2/internal/speech_option_defaults.h @@ -21,13 +21,14 @@ #include "google/cloud/options.h" #include "google/cloud/version.h" +#include namespace google { namespace cloud { namespace speech_v2_internal { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -Options SpeechDefaultOptions(Options options); +Options SpeechDefaultOptions(std::string const& location, Options options); GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END } // namespace speech_v2_internal diff --git a/google/cloud/speech/v2/speech_connection.cc b/google/cloud/speech/v2/speech_connection.cc index b276fe0ca6e0..dc42f03d72bc 100644 --- a/google/cloud/speech/v2/speech_connection.cc +++ b/google/cloud/speech/v2/speech_connection.cc @@ -209,11 +209,13 @@ SpeechConnection::UndeletePhraseSet( Status(StatusCode::kUnimplemented, "not implemented")); } -std::shared_ptr MakeSpeechConnection(Options options) { +std::shared_ptr MakeSpeechConnection( + std::string const& location, Options options) { internal::CheckExpectedOptions(options, __func__); - options = speech_v2_internal::SpeechDefaultOptions(std::move(options)); + options = + speech_v2_internal::SpeechDefaultOptions(location, std::move(options)); auto background = internal::MakeBackgroundThreadsFactory(options)(); auto auth = internal::CreateAuthenticationStrategy(background->cq(), options); auto stub = @@ -223,6 +225,10 @@ std::shared_ptr MakeSpeechConnection(Options options) { std::move(background), std::move(stub), std::move(options))); } +std::shared_ptr MakeSpeechConnection(Options options) { + return MakeSpeechConnection(std::string{}, std::move(options)); +} + GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END } // namespace speech_v2 } // namespace cloud diff --git a/google/cloud/speech/v2/speech_connection.h b/google/cloud/speech/v2/speech_connection.h index 2acd172bfb28..e37e66a860ef 100644 --- a/google/cloud/speech/v2/speech_connection.h +++ b/google/cloud/speech/v2/speech_connection.h @@ -33,6 +33,7 @@ #include #include #include +#include namespace google { namespace cloud { @@ -285,9 +286,20 @@ class SpeechConnection { * @note Unexpected options will be ignored. To log unexpected options instead, * set `GOOGLE_CLOUD_CPP_ENABLE_CLOG=yes` in the environment. * + * @param location Sets the prefix for the default `EndpointOption` value. * @param options (optional) Configure the `SpeechConnection` created by * this function. */ +std::shared_ptr MakeSpeechConnection( + std::string const& location, Options options = {}); + +/** + * A backwards-compatible version of the previous factory function. Unless + * the service also offers a global endpoint, the default value of the + * `EndpointOption` may be useless, in which case it must be overridden. + * + * @deprecated Please use the `location` overload instead. + */ std::shared_ptr MakeSpeechConnection(Options options = {}); GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END