google_cloud_speech_v2/
client.rs

1// Copyright 2025 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Code generated by sidekick. DO NOT EDIT.
16#![allow(rustdoc::redundant_explicit_links)]
17#![allow(rustdoc::broken_intra_doc_links)]
18
19/// Implements a client for the Cloud Speech-to-Text API.
20///
21/// # Example
22/// ```
23/// # tokio_test::block_on(async {
24/// # use google_cloud_speech_v2::client::Speech;
25/// let client = Speech::builder().build().await?;
26/// // use `client` to make requests to the Cloud Speech-to-Text API.
27/// # gax::client_builder::Result::<()>::Ok(()) });
28/// ```
29///
30/// # Service Description
31///
32/// Enables speech transcription and resource management.
33///
34/// # Configuration
35///
36/// To configure `Speech` use the `with_*` methods in the type returned
37/// by [builder()][Speech::builder]. The default configuration should
38/// work for most applications. Common configuration changes include
39///
40/// * [with_endpoint()]: by default this client uses the global default endpoint
41///   (`https://speech.googleapis.com`). Applications using regional
42///   endpoints or running in restricted networks (e.g. a network configured
43//    with [Private Google Access with VPC Service Controls]) may want to
44///   override this default.
45/// * [with_credentials()]: by default this client uses
46///   [Application Default Credentials]. Applications using custom
47///   authentication may need to override this default.
48///
49/// [with_endpoint()]: super::builder::speech::ClientBuilder::with_endpoint
50/// [with_credentials()]: super::builder::speech::ClientBuilder::credentials
51/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
52/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
53///
54/// # Pooling and Cloning
55///
56/// `Speech` holds a connection pool internally, it is advised to
57/// create one and the reuse it.  You do not need to wrap `Speech` in
58/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
59/// already uses an `Arc` internally.
60#[derive(Clone, Debug)]
61pub struct Speech {
62    inner: std::sync::Arc<dyn super::stub::dynamic::Speech>,
63}
64
65impl Speech {
66    /// Returns a builder for [Speech].
67    ///
68    /// ```
69    /// # tokio_test::block_on(async {
70    /// # use google_cloud_speech_v2::client::Speech;
71    /// let client = Speech::builder().build().await?;
72    /// # gax::client_builder::Result::<()>::Ok(()) });
73    /// ```
74    pub fn builder() -> super::builder::speech::ClientBuilder {
75        gax::client_builder::internal::new_builder(super::builder::speech::client::Factory)
76    }
77
78    /// Creates a new client from the provided stub.
79    ///
80    /// The most common case for calling this function is in tests mocking the
81    /// client's behavior.
82    pub fn from_stub<T>(stub: T) -> Self
83    where
84        T: super::stub::Speech + 'static,
85    {
86        Self {
87            inner: std::sync::Arc::new(stub),
88        }
89    }
90
91    pub(crate) async fn new(
92        config: gaxi::options::ClientConfig,
93    ) -> gax::client_builder::Result<Self> {
94        let inner = Self::build_inner(config).await?;
95        Ok(Self { inner })
96    }
97
98    async fn build_inner(
99        conf: gaxi::options::ClientConfig,
100    ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::Speech>> {
101        if gaxi::options::tracing_enabled(&conf) {
102            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
103        }
104        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
105    }
106
107    async fn build_transport(
108        conf: gaxi::options::ClientConfig,
109    ) -> gax::client_builder::Result<impl super::stub::Speech> {
110        super::transport::Speech::new(conf).await
111    }
112
113    async fn build_with_tracing(
114        conf: gaxi::options::ClientConfig,
115    ) -> gax::client_builder::Result<impl super::stub::Speech> {
116        Self::build_transport(conf)
117            .await
118            .map(super::tracing::Speech::new)
119    }
120
121    /// Creates a [Recognizer][google.cloud.speech.v2.Recognizer].
122    ///
123    /// [google.cloud.speech.v2.Recognizer]: crate::model::Recognizer
124    ///
125    /// # Long running operations
126    ///
127    /// This method is used to start, and/or poll a [long-running Operation].
128    /// The [Working with long-running operations] chapter in the [user guide]
129    /// covers these operations in detail.
130    ///
131    /// [long-running operation]: https://google.aip.dev/151
132    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
133    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
134    pub fn create_recognizer(&self) -> super::builder::speech::CreateRecognizer {
135        super::builder::speech::CreateRecognizer::new(self.inner.clone())
136    }
137
138    /// Lists Recognizers.
139    pub fn list_recognizers(&self) -> super::builder::speech::ListRecognizers {
140        super::builder::speech::ListRecognizers::new(self.inner.clone())
141    }
142
143    /// Returns the requested
144    /// [Recognizer][google.cloud.speech.v2.Recognizer]. Fails with
145    /// [NOT_FOUND][google.rpc.Code.NOT_FOUND] if the requested Recognizer doesn't
146    /// exist.
147    ///
148    /// [google.cloud.speech.v2.Recognizer]: crate::model::Recognizer
149    pub fn get_recognizer(&self) -> super::builder::speech::GetRecognizer {
150        super::builder::speech::GetRecognizer::new(self.inner.clone())
151    }
152
153    /// Updates the [Recognizer][google.cloud.speech.v2.Recognizer].
154    ///
155    /// [google.cloud.speech.v2.Recognizer]: crate::model::Recognizer
156    ///
157    /// # Long running operations
158    ///
159    /// This method is used to start, and/or poll a [long-running Operation].
160    /// The [Working with long-running operations] chapter in the [user guide]
161    /// covers these operations in detail.
162    ///
163    /// [long-running operation]: https://google.aip.dev/151
164    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
165    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
166    pub fn update_recognizer(&self) -> super::builder::speech::UpdateRecognizer {
167        super::builder::speech::UpdateRecognizer::new(self.inner.clone())
168    }
169
170    /// Deletes the [Recognizer][google.cloud.speech.v2.Recognizer].
171    ///
172    /// [google.cloud.speech.v2.Recognizer]: crate::model::Recognizer
173    ///
174    /// # Long running operations
175    ///
176    /// This method is used to start, and/or poll a [long-running Operation].
177    /// The [Working with long-running operations] chapter in the [user guide]
178    /// covers these operations in detail.
179    ///
180    /// [long-running operation]: https://google.aip.dev/151
181    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
182    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
183    pub fn delete_recognizer(&self) -> super::builder::speech::DeleteRecognizer {
184        super::builder::speech::DeleteRecognizer::new(self.inner.clone())
185    }
186
187    /// Undeletes the [Recognizer][google.cloud.speech.v2.Recognizer].
188    ///
189    /// [google.cloud.speech.v2.Recognizer]: crate::model::Recognizer
190    ///
191    /// # Long running operations
192    ///
193    /// This method is used to start, and/or poll a [long-running Operation].
194    /// The [Working with long-running operations] chapter in the [user guide]
195    /// covers these operations in detail.
196    ///
197    /// [long-running operation]: https://google.aip.dev/151
198    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
199    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
200    pub fn undelete_recognizer(&self) -> super::builder::speech::UndeleteRecognizer {
201        super::builder::speech::UndeleteRecognizer::new(self.inner.clone())
202    }
203
204    /// Performs synchronous Speech recognition: receive results after all audio
205    /// has been sent and processed.
206    pub fn recognize(&self) -> super::builder::speech::Recognize {
207        super::builder::speech::Recognize::new(self.inner.clone())
208    }
209
210    /// Performs batch asynchronous speech recognition: send a request with N
211    /// audio files and receive a long running operation that can be polled to see
212    /// when the transcriptions are finished.
213    ///
214    /// # Long running operations
215    ///
216    /// This method is used to start, and/or poll a [long-running Operation].
217    /// The [Working with long-running operations] chapter in the [user guide]
218    /// covers these operations in detail.
219    ///
220    /// [long-running operation]: https://google.aip.dev/151
221    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
222    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
223    pub fn batch_recognize(&self) -> super::builder::speech::BatchRecognize {
224        super::builder::speech::BatchRecognize::new(self.inner.clone())
225    }
226
227    /// Returns the requested [Config][google.cloud.speech.v2.Config].
228    ///
229    /// [google.cloud.speech.v2.Config]: crate::model::Config
230    pub fn get_config(&self) -> super::builder::speech::GetConfig {
231        super::builder::speech::GetConfig::new(self.inner.clone())
232    }
233
234    /// Updates the [Config][google.cloud.speech.v2.Config].
235    ///
236    /// [google.cloud.speech.v2.Config]: crate::model::Config
237    pub fn update_config(&self) -> super::builder::speech::UpdateConfig {
238        super::builder::speech::UpdateConfig::new(self.inner.clone())
239    }
240
241    /// Creates a [CustomClass][google.cloud.speech.v2.CustomClass].
242    ///
243    /// [google.cloud.speech.v2.CustomClass]: crate::model::CustomClass
244    ///
245    /// # Long running operations
246    ///
247    /// This method is used to start, and/or poll a [long-running Operation].
248    /// The [Working with long-running operations] chapter in the [user guide]
249    /// covers these operations in detail.
250    ///
251    /// [long-running operation]: https://google.aip.dev/151
252    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
253    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
254    pub fn create_custom_class(&self) -> super::builder::speech::CreateCustomClass {
255        super::builder::speech::CreateCustomClass::new(self.inner.clone())
256    }
257
258    /// Lists CustomClasses.
259    pub fn list_custom_classes(&self) -> super::builder::speech::ListCustomClasses {
260        super::builder::speech::ListCustomClasses::new(self.inner.clone())
261    }
262
263    /// Returns the requested
264    /// [CustomClass][google.cloud.speech.v2.CustomClass].
265    ///
266    /// [google.cloud.speech.v2.CustomClass]: crate::model::CustomClass
267    pub fn get_custom_class(&self) -> super::builder::speech::GetCustomClass {
268        super::builder::speech::GetCustomClass::new(self.inner.clone())
269    }
270
271    /// Updates the [CustomClass][google.cloud.speech.v2.CustomClass].
272    ///
273    /// [google.cloud.speech.v2.CustomClass]: crate::model::CustomClass
274    ///
275    /// # Long running operations
276    ///
277    /// This method is used to start, and/or poll a [long-running Operation].
278    /// The [Working with long-running operations] chapter in the [user guide]
279    /// covers these operations in detail.
280    ///
281    /// [long-running operation]: https://google.aip.dev/151
282    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
283    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
284    pub fn update_custom_class(&self) -> super::builder::speech::UpdateCustomClass {
285        super::builder::speech::UpdateCustomClass::new(self.inner.clone())
286    }
287
288    /// Deletes the [CustomClass][google.cloud.speech.v2.CustomClass].
289    ///
290    /// [google.cloud.speech.v2.CustomClass]: crate::model::CustomClass
291    ///
292    /// # Long running operations
293    ///
294    /// This method is used to start, and/or poll a [long-running Operation].
295    /// The [Working with long-running operations] chapter in the [user guide]
296    /// covers these operations in detail.
297    ///
298    /// [long-running operation]: https://google.aip.dev/151
299    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
300    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
301    pub fn delete_custom_class(&self) -> super::builder::speech::DeleteCustomClass {
302        super::builder::speech::DeleteCustomClass::new(self.inner.clone())
303    }
304
305    /// Undeletes the [CustomClass][google.cloud.speech.v2.CustomClass].
306    ///
307    /// [google.cloud.speech.v2.CustomClass]: crate::model::CustomClass
308    ///
309    /// # Long running operations
310    ///
311    /// This method is used to start, and/or poll a [long-running Operation].
312    /// The [Working with long-running operations] chapter in the [user guide]
313    /// covers these operations in detail.
314    ///
315    /// [long-running operation]: https://google.aip.dev/151
316    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
317    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
318    pub fn undelete_custom_class(&self) -> super::builder::speech::UndeleteCustomClass {
319        super::builder::speech::UndeleteCustomClass::new(self.inner.clone())
320    }
321
322    /// Creates a [PhraseSet][google.cloud.speech.v2.PhraseSet].
323    ///
324    /// [google.cloud.speech.v2.PhraseSet]: crate::model::PhraseSet
325    ///
326    /// # Long running operations
327    ///
328    /// This method is used to start, and/or poll a [long-running Operation].
329    /// The [Working with long-running operations] chapter in the [user guide]
330    /// covers these operations in detail.
331    ///
332    /// [long-running operation]: https://google.aip.dev/151
333    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
334    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
335    pub fn create_phrase_set(&self) -> super::builder::speech::CreatePhraseSet {
336        super::builder::speech::CreatePhraseSet::new(self.inner.clone())
337    }
338
339    /// Lists PhraseSets.
340    pub fn list_phrase_sets(&self) -> super::builder::speech::ListPhraseSets {
341        super::builder::speech::ListPhraseSets::new(self.inner.clone())
342    }
343
344    /// Returns the requested
345    /// [PhraseSet][google.cloud.speech.v2.PhraseSet].
346    ///
347    /// [google.cloud.speech.v2.PhraseSet]: crate::model::PhraseSet
348    pub fn get_phrase_set(&self) -> super::builder::speech::GetPhraseSet {
349        super::builder::speech::GetPhraseSet::new(self.inner.clone())
350    }
351
352    /// Updates the [PhraseSet][google.cloud.speech.v2.PhraseSet].
353    ///
354    /// [google.cloud.speech.v2.PhraseSet]: crate::model::PhraseSet
355    ///
356    /// # Long running operations
357    ///
358    /// This method is used to start, and/or poll a [long-running Operation].
359    /// The [Working with long-running operations] chapter in the [user guide]
360    /// covers these operations in detail.
361    ///
362    /// [long-running operation]: https://google.aip.dev/151
363    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
364    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
365    pub fn update_phrase_set(&self) -> super::builder::speech::UpdatePhraseSet {
366        super::builder::speech::UpdatePhraseSet::new(self.inner.clone())
367    }
368
369    /// Deletes the [PhraseSet][google.cloud.speech.v2.PhraseSet].
370    ///
371    /// [google.cloud.speech.v2.PhraseSet]: crate::model::PhraseSet
372    ///
373    /// # Long running operations
374    ///
375    /// This method is used to start, and/or poll a [long-running Operation].
376    /// The [Working with long-running operations] chapter in the [user guide]
377    /// covers these operations in detail.
378    ///
379    /// [long-running operation]: https://google.aip.dev/151
380    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
381    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
382    pub fn delete_phrase_set(&self) -> super::builder::speech::DeletePhraseSet {
383        super::builder::speech::DeletePhraseSet::new(self.inner.clone())
384    }
385
386    /// Undeletes the [PhraseSet][google.cloud.speech.v2.PhraseSet].
387    ///
388    /// [google.cloud.speech.v2.PhraseSet]: crate::model::PhraseSet
389    ///
390    /// # Long running operations
391    ///
392    /// This method is used to start, and/or poll a [long-running Operation].
393    /// The [Working with long-running operations] chapter in the [user guide]
394    /// covers these operations in detail.
395    ///
396    /// [long-running operation]: https://google.aip.dev/151
397    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
398    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
399    pub fn undelete_phrase_set(&self) -> super::builder::speech::UndeletePhraseSet {
400        super::builder::speech::UndeletePhraseSet::new(self.inner.clone())
401    }
402
403    /// Lists information about the supported locations for this service.
404    pub fn list_locations(&self) -> super::builder::speech::ListLocations {
405        super::builder::speech::ListLocations::new(self.inner.clone())
406    }
407
408    /// Gets information about a location.
409    pub fn get_location(&self) -> super::builder::speech::GetLocation {
410        super::builder::speech::GetLocation::new(self.inner.clone())
411    }
412
413    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
414    ///
415    /// [google.longrunning.Operations]: longrunning::client::Operations
416    pub fn list_operations(&self) -> super::builder::speech::ListOperations {
417        super::builder::speech::ListOperations::new(self.inner.clone())
418    }
419
420    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
421    ///
422    /// [google.longrunning.Operations]: longrunning::client::Operations
423    pub fn get_operation(&self) -> super::builder::speech::GetOperation {
424        super::builder::speech::GetOperation::new(self.inner.clone())
425    }
426
427    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
428    ///
429    /// [google.longrunning.Operations]: longrunning::client::Operations
430    pub fn delete_operation(&self) -> super::builder::speech::DeleteOperation {
431        super::builder::speech::DeleteOperation::new(self.inner.clone())
432    }
433
434    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
435    ///
436    /// [google.longrunning.Operations]: longrunning::client::Operations
437    pub fn cancel_operation(&self) -> super::builder::speech::CancelOperation {
438        super::builder::speech::CancelOperation::new(self.inner.clone())
439    }
440}