1 // Copyright 2020 Google LLC. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Code generated file. DO NOT EDIT. 6 7 // Package speech provides access to the Cloud Speech API. 8 // 9 // This package is DEPRECATED. Use package cloud.google.com/go/speech/apiv1 instead. 10 // 11 // For product documentation, see: https://cloud.google.com/speech-to-text/docs/quickstart-protocol 12 // 13 // # Creating a client 14 // 15 // Usage example: 16 // 17 // import "google.golang.org/api/speech/v1beta1" 18 // ... 19 // ctx := context.Background() 20 // speechService, err := speech.NewService(ctx) 21 // 22 // In this example, Google Application Default Credentials are used for authentication. 23 // 24 // For information on how to create and obtain Application Default Credentials, see https://developers.google.com/identity/protocols/application-default-credentials. 25 // 26 // # Other authentication options 27 // 28 // To use an API key for authentication (note: some APIs do not support API keys), use option.WithAPIKey: 29 // 30 // speechService, err := speech.NewService(ctx, option.WithAPIKey("AIza...")) 31 // 32 // To use an OAuth token (e.g., a user token obtained via a three-legged OAuth flow), use option.WithTokenSource: 33 // 34 // config := &oauth2.Config{...} 35 // // ... 36 // token, err := config.Exchange(ctx, ...) 37 // speechService, err := speech.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token))) 38 // 39 // See https://godoc.org/google.golang.org/api/option/ for details on options. 40 package speech // import "google.golang.org/api/speech/v1beta1" 41 42 import ( 43 "bytes" 44 "context" 45 "encoding/json" 46 "errors" 47 "fmt" 48 "io" 49 "net/http" 50 "net/url" 51 "strconv" 52 "strings" 53 54 googleapi "google.golang.org/api/googleapi" 55 gensupport "google.golang.org/api/internal/gensupport" 56 option "google.golang.org/api/option" 57 htransport "google.golang.org/api/transport/http" 58 ) 59 60 // Always reference these packages, just in case the auto-generated code 61 // below doesn't. 62 var _ = bytes.NewBuffer 63 var _ = strconv.Itoa 64 var _ = fmt.Sprintf 65 var _ = json.NewDecoder 66 var _ = io.Copy 67 var _ = url.Parse 68 var _ = gensupport.MarshalJSON 69 var _ = googleapi.Version 70 var _ = errors.New 71 var _ = strings.Replace 72 var _ = context.Canceled 73 74 const apiId = "speech:v1beta1" 75 const apiName = "speech" 76 const apiVersion = "v1beta1" 77 const basePath = "https://speech.googleapis.com/" 78 79 // OAuth2 scopes used by this API. 80 const ( 81 // View and manage your data across Google Cloud Platform services 82 CloudPlatformScope = "https://www.googleapis.com/auth/cloud-platform" 83 ) 84 85 // NewService creates a new Service. 86 func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) { 87 scopesOption := option.WithScopes( 88 "https://www.googleapis.com/auth/cloud-platform", 89 ) 90 // NOTE: prepend, so we don't override user-specified scopes. 91 opts = append([]option.ClientOption{scopesOption}, opts...) 92 client, endpoint, err := htransport.NewClient(ctx, opts...) 93 if err != nil { 94 return nil, err 95 } 96 s, err := New(client) 97 if err != nil { 98 return nil, err 99 } 100 if endpoint != "" { 101 s.BasePath = endpoint 102 } 103 return s, nil 104 } 105 106 // New creates a new Service. It uses the provided http.Client for requests. 107 // 108 // Deprecated: please use NewService instead. 109 // To provide a custom HTTP client, use option.WithHTTPClient. 110 // If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead. 111 func New(client *http.Client) (*Service, error) { 112 if client == nil { 113 return nil, errors.New("client is nil") 114 } 115 s := &Service{client: client, BasePath: basePath} 116 s.Operations = NewOperationsService(s) 117 s.Speech = NewSpeechService(s) 118 return s, nil 119 } 120 121 type Service struct { 122 client *http.Client 123 BasePath string // API endpoint base URL 124 UserAgent string // optional additional User-Agent fragment 125 126 Operations *OperationsService 127 128 Speech *SpeechService 129 } 130 131 func (s *Service) userAgent() string { 132 if s.UserAgent == "" { 133 return googleapi.UserAgent 134 } 135 return googleapi.UserAgent + " " + s.UserAgent 136 } 137 138 func NewOperationsService(s *Service) *OperationsService { 139 rs := &OperationsService{s: s} 140 return rs 141 } 142 143 type OperationsService struct { 144 s *Service 145 } 146 147 func NewSpeechService(s *Service) *SpeechService { 148 rs := &SpeechService{s: s} 149 return rs 150 } 151 152 type SpeechService struct { 153 s *Service 154 } 155 156 // AsyncRecognizeRequest: The top-level message sent by the client for 157 // the `AsyncRecognize` method. 158 type AsyncRecognizeRequest struct { 159 // Audio: *Required* The audio data to be recognized. 160 Audio *RecognitionAudio `json:"audio,omitempty"` 161 162 // Config: *Required* Provides information to the recognizer that 163 // specifies how to 164 // process the request. 165 Config *RecognitionConfig `json:"config,omitempty"` 166 167 // ForceSendFields is a list of field names (e.g. "Audio") to 168 // unconditionally include in API requests. By default, fields with 169 // empty values are omitted from API requests. However, any non-pointer, 170 // non-interface field appearing in ForceSendFields will be sent to the 171 // server regardless of whether the field is empty or not. This may be 172 // used to include empty fields in Patch requests. 173 ForceSendFields []string `json:"-"` 174 175 // NullFields is a list of field names (e.g. "Audio") to include in API 176 // requests with the JSON null value. By default, fields with empty 177 // values are omitted from API requests. However, any field with an 178 // empty value appearing in NullFields will be sent to the server as 179 // null. It is an error if a field in this list has a non-empty value. 180 // This may be used to include null fields in Patch requests. 181 NullFields []string `json:"-"` 182 } 183 184 func (s *AsyncRecognizeRequest) MarshalJSON() ([]byte, error) { 185 type NoMethod AsyncRecognizeRequest 186 raw := NoMethod(*s) 187 return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields) 188 } 189 190 // ListOperationsResponse: The response message for 191 // Operations.ListOperations. 192 type ListOperationsResponse struct { 193 // NextPageToken: The standard List next-page token. 194 NextPageToken string `json:"nextPageToken,omitempty"` 195 196 // Operations: A list of operations that matches the specified filter in 197 // the request. 198 Operations []*Operation `json:"operations,omitempty"` 199 200 // ServerResponse contains the HTTP response code and headers from the 201 // server. 202 googleapi.ServerResponse `json:"-"` 203 204 // ForceSendFields is a list of field names (e.g. "NextPageToken") to 205 // unconditionally include in API requests. By default, fields with 206 // empty values are omitted from API requests. However, any non-pointer, 207 // non-interface field appearing in ForceSendFields will be sent to the 208 // server regardless of whether the field is empty or not. This may be 209 // used to include empty fields in Patch requests. 210 ForceSendFields []string `json:"-"` 211 212 // NullFields is a list of field names (e.g. "NextPageToken") to include 213 // in API requests with the JSON null value. By default, fields with 214 // empty values are omitted from API requests. However, any field with 215 // an empty value appearing in NullFields will be sent to the server as 216 // null. It is an error if a field in this list has a non-empty value. 217 // This may be used to include null fields in Patch requests. 218 NullFields []string `json:"-"` 219 } 220 221 func (s *ListOperationsResponse) MarshalJSON() ([]byte, error) { 222 type NoMethod ListOperationsResponse 223 raw := NoMethod(*s) 224 return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields) 225 } 226 227 // Operation: This resource represents a long-running operation that is 228 // the result of a 229 // network API call. 230 type Operation struct { 231 // Done: If the value is `false`, it means the operation is still in 232 // progress. 233 // If `true`, the operation is completed, and either `error` or 234 // `response` is 235 // available. 236 Done bool `json:"done,omitempty"` 237 238 // Error: The error result of the operation in case of failure or 239 // cancellation. 240 Error *Status `json:"error,omitempty"` 241 242 // Metadata: Service-specific metadata associated with the operation. 243 // It typically 244 // contains progress information and common metadata such as create 245 // time. 246 // Some services might not provide such metadata. Any method that 247 // returns a 248 // long-running operation should document the metadata type, if any. 249 Metadata googleapi.RawMessage `json:"metadata,omitempty"` 250 251 // Name: The server-assigned name, which is only unique within the same 252 // service that 253 // originally returns it. If you use the default HTTP mapping, 254 // the 255 // `name` should have the format of `operations/some/unique/name`. 256 Name string `json:"name,omitempty"` 257 258 // Response: The normal response of the operation in case of success. 259 // If the original 260 // method returns no data on success, such as `Delete`, the response 261 // is 262 // `google.protobuf.Empty`. If the original method is 263 // standard 264 // `Get`/`Create`/`Update`, the response should be the resource. For 265 // other 266 // methods, the response should have the type `XxxResponse`, where 267 // `Xxx` 268 // is the original method name. For example, if the original method 269 // name 270 // is `TakeSnapshot()`, the inferred response type 271 // is 272 // `TakeSnapshotResponse`. 273 Response googleapi.RawMessage `json:"response,omitempty"` 274 275 // ServerResponse contains the HTTP response code and headers from the 276 // server. 277 googleapi.ServerResponse `json:"-"` 278 279 // ForceSendFields is a list of field names (e.g. "Done") to 280 // unconditionally include in API requests. By default, fields with 281 // empty values are omitted from API requests. However, any non-pointer, 282 // non-interface field appearing in ForceSendFields will be sent to the 283 // server regardless of whether the field is empty or not. This may be 284 // used to include empty fields in Patch requests. 285 ForceSendFields []string `json:"-"` 286 287 // NullFields is a list of field names (e.g. "Done") to include in API 288 // requests with the JSON null value. By default, fields with empty 289 // values are omitted from API requests. However, any field with an 290 // empty value appearing in NullFields will be sent to the server as 291 // null. It is an error if a field in this list has a non-empty value. 292 // This may be used to include null fields in Patch requests. 293 NullFields []string `json:"-"` 294 } 295 296 func (s *Operation) MarshalJSON() ([]byte, error) { 297 type NoMethod Operation 298 raw := NoMethod(*s) 299 return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields) 300 } 301 302 // RecognitionAudio: Contains audio data in the encoding specified in 303 // the `RecognitionConfig`. 304 // Either `content` or `uri` must be supplied. Supplying both or 305 // neither 306 // returns google.rpc.Code.INVALID_ARGUMENT. See 307 // [audio limits](https://cloud.google.com/speech/limits#content). 308 type RecognitionAudio struct { 309 // Content: The audio data bytes encoded as specified 310 // in 311 // `RecognitionConfig`. Note: as with all bytes fields, protobuffers use 312 // a 313 // pure binary representation, whereas JSON representations use base64. 314 Content string `json:"content,omitempty"` 315 316 // Uri: URI that points to a file that contains audio data bytes as 317 // specified in 318 // `RecognitionConfig`. Currently, only Google Cloud Storage URIs 319 // are 320 // supported, which must be specified in the following 321 // format: 322 // `gs://bucket_name/object_name` (other URI formats 323 // return 324 // google.rpc.Code.INVALID_ARGUMENT). For more information, see 325 // [Request URIs](https://cloud.google.com/storage/docs/reference-uris). 326 Uri string `json:"uri,omitempty"` 327 328 // ForceSendFields is a list of field names (e.g. "Content") to 329 // unconditionally include in API requests. By default, fields with 330 // empty values are omitted from API requests. However, any non-pointer, 331 // non-interface field appearing in ForceSendFields will be sent to the 332 // server regardless of whether the field is empty or not. This may be 333 // used to include empty fields in Patch requests. 334 ForceSendFields []string `json:"-"` 335 336 // NullFields is a list of field names (e.g. "Content") to include in 337 // API requests with the JSON null value. By default, fields with empty 338 // values are omitted from API requests. However, any field with an 339 // empty value appearing in NullFields will be sent to the server as 340 // null. It is an error if a field in this list has a non-empty value. 341 // This may be used to include null fields in Patch requests. 342 NullFields []string `json:"-"` 343 } 344 345 func (s *RecognitionAudio) MarshalJSON() ([]byte, error) { 346 type NoMethod RecognitionAudio 347 raw := NoMethod(*s) 348 return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields) 349 } 350 351 // RecognitionConfig: Provides information to the recognizer that 352 // specifies how to process the 353 // request. 354 type RecognitionConfig struct { 355 // Encoding: *Required* Encoding of audio data sent in all 356 // `RecognitionAudio` messages. 357 // 358 // Possible values: 359 // "ENCODING_UNSPECIFIED" - Not specified. Will return result 360 // google.rpc.Code.INVALID_ARGUMENT. 361 // "LINEAR16" - Uncompressed 16-bit signed little-endian samples 362 // (Linear PCM). 363 // This is the only encoding that may be used by `AsyncRecognize`. 364 // "FLAC" - This is the recommended encoding for `SyncRecognize` 365 // and 366 // `StreamingRecognize` because it uses lossless compression; 367 // therefore 368 // recognition accuracy is not compromised by a lossy codec. 369 // 370 // The stream FLAC (Free Lossless Audio Codec) encoding is specified 371 // at: 372 // http://flac.sourceforge.net/documentation.html. 373 // 16-bit and 24-bit samples are supported. 374 // Not all fields in STREAMINFO are supported. 375 // "MULAW" - 8-bit samples that compand 14-bit audio samples using 376 // G.711 PCMU/mu-law. 377 // "AMR" - Adaptive Multi-Rate Narrowband codec. `sample_rate` must be 378 // 8000 Hz. 379 // "AMR_WB" - Adaptive Multi-Rate Wideband codec. `sample_rate` must 380 // be 16000 Hz. 381 Encoding string `json:"encoding,omitempty"` 382 383 // LanguageCode: *Optional* The language of the supplied audio as a 384 // BCP-47 language tag. 385 // Example: "en-GB" https://www.rfc-editor.org/rfc/bcp/bcp47.txt 386 // If omitted, defaults to "en-US". See 387 // [Language 388 // Support](https://cloud.google.com/speech/docs/languages) 389 // for a list of the currently supported language codes. 390 LanguageCode string `json:"languageCode,omitempty"` 391 392 // MaxAlternatives: *Optional* Maximum number of recognition hypotheses 393 // to be returned. 394 // Specifically, the maximum number of `SpeechRecognitionAlternative` 395 // messages 396 // within each `SpeechRecognitionResult`. 397 // The server may return fewer than `max_alternatives`. 398 // Valid values are `0`-`30`. A value of `0` or `1` will return a 399 // maximum of 400 // one. If omitted, will return a maximum of one. 401 MaxAlternatives int64 `json:"maxAlternatives,omitempty"` 402 403 // ProfanityFilter: *Optional* If set to `true`, the server will attempt 404 // to filter out 405 // profanities, replacing all but the initial character in each filtered 406 // word 407 // with asterisks, e.g. "f***". If set to `false` or omitted, 408 // profanities 409 // won't be filtered out. 410 ProfanityFilter bool `json:"profanityFilter,omitempty"` 411 412 // SampleRate: *Required* Sample rate in Hertz of the audio data sent in 413 // all 414 // `RecognitionAudio` messages. Valid values are: 8000-48000. 415 // 16000 is optimal. For best results, set the sampling rate of the 416 // audio 417 // source to 16000 Hz. If that's not possible, use the native sample 418 // rate of 419 // the audio source (instead of re-sampling). 420 SampleRate int64 `json:"sampleRate,omitempty"` 421 422 // SpeechContext: *Optional* A means to provide context to assist the 423 // speech recognition. 424 SpeechContext *SpeechContext `json:"speechContext,omitempty"` 425 426 // ForceSendFields is a list of field names (e.g. "Encoding") to 427 // unconditionally include in API requests. By default, fields with 428 // empty values are omitted from API requests. However, any non-pointer, 429 // non-interface field appearing in ForceSendFields will be sent to the 430 // server regardless of whether the field is empty or not. This may be 431 // used to include empty fields in Patch requests. 432 ForceSendFields []string `json:"-"` 433 434 // NullFields is a list of field names (e.g. "Encoding") to include in 435 // API requests with the JSON null value. By default, fields with empty 436 // values are omitted from API requests. However, any field with an 437 // empty value appearing in NullFields will be sent to the server as 438 // null. It is an error if a field in this list has a non-empty value. 439 // This may be used to include null fields in Patch requests. 440 NullFields []string `json:"-"` 441 } 442 443 func (s *RecognitionConfig) MarshalJSON() ([]byte, error) { 444 type NoMethod RecognitionConfig 445 raw := NoMethod(*s) 446 return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields) 447 } 448 449 // SpeechContext: Provides "hints" to the speech recognizer to favor 450 // specific words and phrases 451 // in the results. 452 type SpeechContext struct { 453 // Phrases: *Optional* A list of strings containing words and phrases 454 // "hints" so that 455 // the speech recognition is more likely to recognize them. This can be 456 // used 457 // to improve the accuracy for specific words and phrases, for example, 458 // if 459 // specific commands are typically spoken by the user. This can also be 460 // used 461 // to add additional words to the vocabulary of the recognizer. 462 // See 463 // [usage limits](https://cloud.google.com/speech/limits#content). 464 Phrases []string `json:"phrases,omitempty"` 465 466 // ForceSendFields is a list of field names (e.g. "Phrases") to 467 // unconditionally include in API requests. By default, fields with 468 // empty values are omitted from API requests. However, any non-pointer, 469 // non-interface field appearing in ForceSendFields will be sent to the 470 // server regardless of whether the field is empty or not. This may be 471 // used to include empty fields in Patch requests. 472 ForceSendFields []string `json:"-"` 473 474 // NullFields is a list of field names (e.g. "Phrases") to include in 475 // API requests with the JSON null value. By default, fields with empty 476 // values are omitted from API requests. However, any field with an 477 // empty value appearing in NullFields will be sent to the server as 478 // null. It is an error if a field in this list has a non-empty value. 479 // This may be used to include null fields in Patch requests. 480 NullFields []string `json:"-"` 481 } 482 483 func (s *SpeechContext) MarshalJSON() ([]byte, error) { 484 type NoMethod SpeechContext 485 raw := NoMethod(*s) 486 return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields) 487 } 488 489 // SpeechRecognitionAlternative: Alternative hypotheses (a.k.a. n-best 490 // list). 491 type SpeechRecognitionAlternative struct { 492 // Confidence: *Output-only* The confidence estimate between 0.0 and 493 // 1.0. A higher number 494 // indicates an estimated greater likelihood that the recognized words 495 // are 496 // correct. This field is typically provided only for the top 497 // hypothesis, and 498 // only for `is_final=true` results. Clients should not rely on 499 // the 500 // `confidence` field as it is not guaranteed to be accurate, or even 501 // set, in 502 // any of the results. 503 // The default of 0.0 is a sentinel value indicating `confidence` was 504 // not set. 505 Confidence float64 `json:"confidence,omitempty"` 506 507 // Transcript: *Output-only* Transcript text representing the words that 508 // the user spoke. 509 Transcript string `json:"transcript,omitempty"` 510 511 // ForceSendFields is a list of field names (e.g. "Confidence") to 512 // unconditionally include in API requests. By default, fields with 513 // empty values are omitted from API requests. However, any non-pointer, 514 // non-interface field appearing in ForceSendFields will be sent to the 515 // server regardless of whether the field is empty or not. This may be 516 // used to include empty fields in Patch requests. 517 ForceSendFields []string `json:"-"` 518 519 // NullFields is a list of field names (e.g. "Confidence") to include in 520 // API requests with the JSON null value. By default, fields with empty 521 // values are omitted from API requests. However, any field with an 522 // empty value appearing in NullFields will be sent to the server as 523 // null. It is an error if a field in this list has a non-empty value. 524 // This may be used to include null fields in Patch requests. 525 NullFields []string `json:"-"` 526 } 527 528 func (s *SpeechRecognitionAlternative) MarshalJSON() ([]byte, error) { 529 type NoMethod SpeechRecognitionAlternative 530 raw := NoMethod(*s) 531 return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields) 532 } 533 534 func (s *SpeechRecognitionAlternative) UnmarshalJSON(data []byte) error { 535 type NoMethod SpeechRecognitionAlternative 536 var s1 struct { 537 Confidence gensupport.JSONFloat64 `json:"confidence"` 538 *NoMethod 539 } 540 s1.NoMethod = (*NoMethod)(s) 541 if err := json.Unmarshal(data, &s1); err != nil { 542 return err 543 } 544 s.Confidence = float64(s1.Confidence) 545 return nil 546 } 547 548 // SpeechRecognitionResult: A speech recognition result corresponding to 549 // a portion of the audio. 550 type SpeechRecognitionResult struct { 551 // Alternatives: *Output-only* May contain one or more recognition 552 // hypotheses (up to the 553 // maximum specified in `max_alternatives`). 554 Alternatives []*SpeechRecognitionAlternative `json:"alternatives,omitempty"` 555 556 // ForceSendFields is a list of field names (e.g. "Alternatives") to 557 // unconditionally include in API requests. By default, fields with 558 // empty values are omitted from API requests. However, any non-pointer, 559 // non-interface field appearing in ForceSendFields will be sent to the 560 // server regardless of whether the field is empty or not. This may be 561 // used to include empty fields in Patch requests. 562 ForceSendFields []string `json:"-"` 563 564 // NullFields is a list of field names (e.g. "Alternatives") to include 565 // in API requests with the JSON null value. By default, fields with 566 // empty values are omitted from API requests. However, any field with 567 // an empty value appearing in NullFields will be sent to the server as 568 // null. It is an error if a field in this list has a non-empty value. 569 // This may be used to include null fields in Patch requests. 570 NullFields []string `json:"-"` 571 } 572 573 func (s *SpeechRecognitionResult) MarshalJSON() ([]byte, error) { 574 type NoMethod SpeechRecognitionResult 575 raw := NoMethod(*s) 576 return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields) 577 } 578 579 // Status: The `Status` type defines a logical error model that is 580 // suitable for different 581 // programming environments, including REST APIs and RPC APIs. It is 582 // used by 583 // [gRPC](https://github.com/grpc). The error model is designed to 584 // be: 585 // 586 // - Simple to use and understand for most users 587 // - Flexible enough to meet unexpected needs 588 // 589 // # Overview 590 // 591 // The `Status` message contains three pieces of data: error code, error 592 // message, 593 // and error details. The error code should be an enum value 594 // of 595 // google.rpc.Code, but it may accept additional error codes if needed. 596 // The 597 // error message should be a developer-facing English message that 598 // helps 599 // developers *understand* and *resolve* the error. If a localized 600 // user-facing 601 // error message is needed, put the localized message in the error 602 // details or 603 // localize it in the client. The optional error details may contain 604 // arbitrary 605 // information about the error. There is a predefined set of error 606 // detail types 607 // in the package `google.rpc` that can be used for common error 608 // conditions. 609 // 610 // # Language mapping 611 // 612 // The `Status` message is the logical representation of the error 613 // model, but it 614 // is not necessarily the actual wire format. When the `Status` message 615 // is 616 // exposed in different client libraries and different wire protocols, 617 // it can be 618 // mapped differently. For example, it will likely be mapped to some 619 // exceptions 620 // in Java, but more likely mapped to some error codes in C. 621 // 622 // # Other uses 623 // 624 // The error model and the `Status` message can be used in a variety 625 // of 626 // environments, either with or without APIs, to provide a 627 // consistent developer experience across different 628 // environments. 629 // 630 // Example uses of this error model include: 631 // 632 // - Partial errors. If a service needs to return partial errors to the 633 // client, 634 // 635 // it may embed the `Status` in the normal response to indicate the 636 // 637 // partial 638 // 639 // errors. 640 // 641 // - Workflow errors. A typical workflow has multiple steps. Each step 642 // may 643 // 644 // have a `Status` message for error reporting. 645 // 646 // - Batch operations. If a client uses batch request and batch 647 // response, the 648 // 649 // `Status` message should be used directly inside batch response, 650 // 651 // one for 652 // 653 // each error sub-response. 654 // 655 // - Asynchronous operations. If an API call embeds asynchronous 656 // operation 657 // 658 // results in its response, the status of those operations should 659 // 660 // be 661 // 662 // represented directly using the `Status` message. 663 // 664 // - Logging. If some API errors are stored in logs, the message 665 // `Status` could 666 // 667 // be used directly after any stripping needed for security/privacy 668 // 669 // reasons. 670 type Status struct { 671 // Code: The status code, which should be an enum value of 672 // google.rpc.Code. 673 Code int64 `json:"code,omitempty"` 674 675 // Details: A list of messages that carry the error details. There is a 676 // common set of 677 // message types for APIs to use. 678 Details []googleapi.RawMessage `json:"details,omitempty"` 679 680 // Message: A developer-facing error message, which should be in 681 // English. Any 682 // user-facing error message should be localized and sent in 683 // the 684 // google.rpc.Status.details field, or localized by the client. 685 Message string `json:"message,omitempty"` 686 687 // ForceSendFields is a list of field names (e.g. "Code") to 688 // unconditionally include in API requests. By default, fields with 689 // empty values are omitted from API requests. However, any non-pointer, 690 // non-interface field appearing in ForceSendFields will be sent to the 691 // server regardless of whether the field is empty or not. This may be 692 // used to include empty fields in Patch requests. 693 ForceSendFields []string `json:"-"` 694 695 // NullFields is a list of field names (e.g. "Code") to include in API 696 // requests with the JSON null value. By default, fields with empty 697 // values are omitted from API requests. However, any field with an 698 // empty value appearing in NullFields will be sent to the server as 699 // null. It is an error if a field in this list has a non-empty value. 700 // This may be used to include null fields in Patch requests. 701 NullFields []string `json:"-"` 702 } 703 704 func (s *Status) MarshalJSON() ([]byte, error) { 705 type NoMethod Status 706 raw := NoMethod(*s) 707 return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields) 708 } 709 710 // SyncRecognizeRequest: The top-level message sent by the client for 711 // the `SyncRecognize` method. 712 type SyncRecognizeRequest struct { 713 // Audio: *Required* The audio data to be recognized. 714 Audio *RecognitionAudio `json:"audio,omitempty"` 715 716 // Config: *Required* Provides information to the recognizer that 717 // specifies how to 718 // process the request. 719 Config *RecognitionConfig `json:"config,omitempty"` 720 721 // ForceSendFields is a list of field names (e.g. "Audio") to 722 // unconditionally include in API requests. By default, fields with 723 // empty values are omitted from API requests. However, any non-pointer, 724 // non-interface field appearing in ForceSendFields will be sent to the 725 // server regardless of whether the field is empty or not. This may be 726 // used to include empty fields in Patch requests. 727 ForceSendFields []string `json:"-"` 728 729 // NullFields is a list of field names (e.g. "Audio") to include in API 730 // requests with the JSON null value. By default, fields with empty 731 // values are omitted from API requests. However, any field with an 732 // empty value appearing in NullFields will be sent to the server as 733 // null. It is an error if a field in this list has a non-empty value. 734 // This may be used to include null fields in Patch requests. 735 NullFields []string `json:"-"` 736 } 737 738 func (s *SyncRecognizeRequest) MarshalJSON() ([]byte, error) { 739 type NoMethod SyncRecognizeRequest 740 raw := NoMethod(*s) 741 return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields) 742 } 743 744 // SyncRecognizeResponse: The only message returned to the client by 745 // `SyncRecognize`. method. It 746 // contains the result as zero or more sequential 747 // `SpeechRecognitionResult` 748 // messages. 749 type SyncRecognizeResponse struct { 750 // Results: *Output-only* Sequential list of transcription results 751 // corresponding to 752 // sequential portions of audio. 753 Results []*SpeechRecognitionResult `json:"results,omitempty"` 754 755 // ServerResponse contains the HTTP response code and headers from the 756 // server. 757 googleapi.ServerResponse `json:"-"` 758 759 // ForceSendFields is a list of field names (e.g. "Results") to 760 // unconditionally include in API requests. By default, fields with 761 // empty values are omitted from API requests. However, any non-pointer, 762 // non-interface field appearing in ForceSendFields will be sent to the 763 // server regardless of whether the field is empty or not. This may be 764 // used to include empty fields in Patch requests. 765 ForceSendFields []string `json:"-"` 766 767 // NullFields is a list of field names (e.g. "Results") to include in 768 // API requests with the JSON null value. By default, fields with empty 769 // values are omitted from API requests. However, any field with an 770 // empty value appearing in NullFields will be sent to the server as 771 // null. It is an error if a field in this list has a non-empty value. 772 // This may be used to include null fields in Patch requests. 773 NullFields []string `json:"-"` 774 } 775 776 func (s *SyncRecognizeResponse) MarshalJSON() ([]byte, error) { 777 type NoMethod SyncRecognizeResponse 778 raw := NoMethod(*s) 779 return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields) 780 } 781 782 // method id "speech.operations.get": 783 784 type OperationsGetCall struct { 785 s *Service 786 name string 787 urlParams_ gensupport.URLParams 788 ifNoneMatch_ string 789 ctx_ context.Context 790 header_ http.Header 791 } 792 793 // Get: Gets the latest state of a long-running operation. Clients can 794 // use this 795 // method to poll the operation result at intervals as recommended by 796 // the API 797 // service. 798 func (r *OperationsService) Get(name string) *OperationsGetCall { 799 c := &OperationsGetCall{s: r.s, urlParams_: make(gensupport.URLParams)} 800 c.name = name 801 return c 802 } 803 804 // Fields allows partial responses to be retrieved. See 805 // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse 806 // for more information. 807 func (c *OperationsGetCall) Fields(s ...googleapi.Field) *OperationsGetCall { 808 c.urlParams_.Set("fields", googleapi.CombineFields(s)) 809 return c 810 } 811 812 // IfNoneMatch sets the optional parameter which makes the operation 813 // fail if the object's ETag matches the given value. This is useful for 814 // getting updates only after the object has changed since the last 815 // request. Use googleapi.IsNotModified to check whether the response 816 // error from Do is the result of In-None-Match. 817 func (c *OperationsGetCall) IfNoneMatch(entityTag string) *OperationsGetCall { 818 c.ifNoneMatch_ = entityTag 819 return c 820 } 821 822 // Context sets the context to be used in this call's Do method. Any 823 // pending HTTP request will be aborted if the provided context is 824 // canceled. 825 func (c *OperationsGetCall) Context(ctx context.Context) *OperationsGetCall { 826 c.ctx_ = ctx 827 return c 828 } 829 830 // Header returns an http.Header that can be modified by the caller to 831 // add HTTP headers to the request. 832 func (c *OperationsGetCall) Header() http.Header { 833 if c.header_ == nil { 834 c.header_ = make(http.Header) 835 } 836 return c.header_ 837 } 838 839 func (c *OperationsGetCall) doRequest(alt string) (*http.Response, error) { 840 reqHeaders := make(http.Header) 841 reqHeaders.Set("x-goog-api-client", "gl-go/1.13.7 gdcl/20200203") 842 for k, v := range c.header_ { 843 reqHeaders[k] = v 844 } 845 reqHeaders.Set("User-Agent", c.s.userAgent()) 846 if c.ifNoneMatch_ != "" { 847 reqHeaders.Set("If-None-Match", c.ifNoneMatch_) 848 } 849 var body io.Reader = nil 850 c.urlParams_.Set("alt", alt) 851 c.urlParams_.Set("prettyPrint", "false") 852 urls := googleapi.ResolveRelative(c.s.BasePath, "v1beta1/operations/{+name}") 853 urls += "?" + c.urlParams_.Encode() 854 req, err := http.NewRequest("GET", urls, body) 855 if err != nil { 856 return nil, err 857 } 858 req.Header = reqHeaders 859 googleapi.Expand(req.URL, map[string]string{ 860 "name": c.name, 861 }) 862 return gensupport.SendRequest(c.ctx_, c.s.client, req) 863 } 864 865 // Do executes the "speech.operations.get" call. 866 // Exactly one of *Operation or error will be non-nil. Any non-2xx 867 // status code is an error. Response headers are in either 868 // *Operation.ServerResponse.Header or (if a response was returned at 869 // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified 870 // to check whether the returned error was because 871 // http.StatusNotModified was returned. 872 func (c *OperationsGetCall) Do(opts ...googleapi.CallOption) (*Operation, error) { 873 gensupport.SetOptions(c.urlParams_, opts...) 874 res, err := c.doRequest("json") 875 if res != nil && res.StatusCode == http.StatusNotModified { 876 if res.Body != nil { 877 res.Body.Close() 878 } 879 return nil, &googleapi.Error{ 880 Code: res.StatusCode, 881 Header: res.Header, 882 } 883 } 884 if err != nil { 885 return nil, err 886 } 887 defer googleapi.CloseBody(res) 888 if err := googleapi.CheckResponse(res); err != nil { 889 return nil, err 890 } 891 ret := &Operation{ 892 ServerResponse: googleapi.ServerResponse{ 893 Header: res.Header, 894 HTTPStatusCode: res.StatusCode, 895 }, 896 } 897 target := &ret 898 if err := gensupport.DecodeResponse(target, res); err != nil { 899 return nil, err 900 } 901 return ret, nil 902 // { 903 // "description": "Gets the latest state of a long-running operation. Clients can use this\nmethod to poll the operation result at intervals as recommended by the API\nservice.", 904 // "flatPath": "v1beta1/operations/{operationsId}", 905 // "httpMethod": "GET", 906 // "id": "speech.operations.get", 907 // "parameterOrder": [ 908 // "name" 909 // ], 910 // "parameters": { 911 // "name": { 912 // "description": "The name of the operation resource.", 913 // "location": "path", 914 // "pattern": "^[^/]+$", 915 // "required": true, 916 // "type": "string" 917 // } 918 // }, 919 // "path": "v1beta1/operations/{+name}", 920 // "response": { 921 // "$ref": "Operation" 922 // }, 923 // "scopes": [ 924 // "https://www.googleapis.com/auth/cloud-platform" 925 // ] 926 // } 927 928 } 929 930 // method id "speech.operations.list": 931 932 type OperationsListCall struct { 933 s *Service 934 urlParams_ gensupport.URLParams 935 ifNoneMatch_ string 936 ctx_ context.Context 937 header_ http.Header 938 } 939 940 // List: Lists operations that match the specified filter in the 941 // request. If the 942 // server doesn't support this method, it returns 943 // `UNIMPLEMENTED`. 944 // 945 // NOTE: the `name` binding allows API services to override the 946 // binding 947 // to use different resource name schemes, such as `users/*/operations`. 948 // To 949 // override the binding, API services can add a binding such 950 // as 951 // "/v1/{name=users/*}/operations" to their service configuration. 952 // For backwards compatibility, the default name includes the 953 // operations 954 // collection id, however overriding users must ensure the name 955 // binding 956 // is the parent resource, without the operations collection id. 957 func (r *OperationsService) List() *OperationsListCall { 958 c := &OperationsListCall{s: r.s, urlParams_: make(gensupport.URLParams)} 959 return c 960 } 961 962 // Filter sets the optional parameter "filter": The standard list 963 // filter. 964 func (c *OperationsListCall) Filter(filter string) *OperationsListCall { 965 c.urlParams_.Set("filter", filter) 966 return c 967 } 968 969 // Name sets the optional parameter "name": The name of the operation's 970 // parent resource. 971 func (c *OperationsListCall) Name(name string) *OperationsListCall { 972 c.urlParams_.Set("name", name) 973 return c 974 } 975 976 // PageSize sets the optional parameter "pageSize": The standard list 977 // page size. 978 func (c *OperationsListCall) PageSize(pageSize int64) *OperationsListCall { 979 c.urlParams_.Set("pageSize", fmt.Sprint(pageSize)) 980 return c 981 } 982 983 // PageToken sets the optional parameter "pageToken": The standard list 984 // page token. 985 func (c *OperationsListCall) PageToken(pageToken string) *OperationsListCall { 986 c.urlParams_.Set("pageToken", pageToken) 987 return c 988 } 989 990 // Fields allows partial responses to be retrieved. See 991 // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse 992 // for more information. 993 func (c *OperationsListCall) Fields(s ...googleapi.Field) *OperationsListCall { 994 c.urlParams_.Set("fields", googleapi.CombineFields(s)) 995 return c 996 } 997 998 // IfNoneMatch sets the optional parameter which makes the operation 999 // fail if the object's ETag matches the given value. This is useful for 1000 // getting updates only after the object has changed since the last 1001 // request. Use googleapi.IsNotModified to check whether the response 1002 // error from Do is the result of In-None-Match. 1003 func (c *OperationsListCall) IfNoneMatch(entityTag string) *OperationsListCall { 1004 c.ifNoneMatch_ = entityTag 1005 return c 1006 } 1007 1008 // Context sets the context to be used in this call's Do method. Any 1009 // pending HTTP request will be aborted if the provided context is 1010 // canceled. 1011 func (c *OperationsListCall) Context(ctx context.Context) *OperationsListCall { 1012 c.ctx_ = ctx 1013 return c 1014 } 1015 1016 // Header returns an http.Header that can be modified by the caller to 1017 // add HTTP headers to the request. 1018 func (c *OperationsListCall) Header() http.Header { 1019 if c.header_ == nil { 1020 c.header_ = make(http.Header) 1021 } 1022 return c.header_ 1023 } 1024 1025 func (c *OperationsListCall) doRequest(alt string) (*http.Response, error) { 1026 reqHeaders := make(http.Header) 1027 reqHeaders.Set("x-goog-api-client", "gl-go/1.13.7 gdcl/20200203") 1028 for k, v := range c.header_ { 1029 reqHeaders[k] = v 1030 } 1031 reqHeaders.Set("User-Agent", c.s.userAgent()) 1032 if c.ifNoneMatch_ != "" { 1033 reqHeaders.Set("If-None-Match", c.ifNoneMatch_) 1034 } 1035 var body io.Reader = nil 1036 c.urlParams_.Set("alt", alt) 1037 c.urlParams_.Set("prettyPrint", "false") 1038 urls := googleapi.ResolveRelative(c.s.BasePath, "v1beta1/operations") 1039 urls += "?" + c.urlParams_.Encode() 1040 req, err := http.NewRequest("GET", urls, body) 1041 if err != nil { 1042 return nil, err 1043 } 1044 req.Header = reqHeaders 1045 return gensupport.SendRequest(c.ctx_, c.s.client, req) 1046 } 1047 1048 // Do executes the "speech.operations.list" call. 1049 // Exactly one of *ListOperationsResponse or error will be non-nil. Any 1050 // non-2xx status code is an error. Response headers are in either 1051 // *ListOperationsResponse.ServerResponse.Header or (if a response was 1052 // returned at all) in error.(*googleapi.Error).Header. Use 1053 // googleapi.IsNotModified to check whether the returned error was 1054 // because http.StatusNotModified was returned. 1055 func (c *OperationsListCall) Do(opts ...googleapi.CallOption) (*ListOperationsResponse, error) { 1056 gensupport.SetOptions(c.urlParams_, opts...) 1057 res, err := c.doRequest("json") 1058 if res != nil && res.StatusCode == http.StatusNotModified { 1059 if res.Body != nil { 1060 res.Body.Close() 1061 } 1062 return nil, &googleapi.Error{ 1063 Code: res.StatusCode, 1064 Header: res.Header, 1065 } 1066 } 1067 if err != nil { 1068 return nil, err 1069 } 1070 defer googleapi.CloseBody(res) 1071 if err := googleapi.CheckResponse(res); err != nil { 1072 return nil, err 1073 } 1074 ret := &ListOperationsResponse{ 1075 ServerResponse: googleapi.ServerResponse{ 1076 Header: res.Header, 1077 HTTPStatusCode: res.StatusCode, 1078 }, 1079 } 1080 target := &ret 1081 if err := gensupport.DecodeResponse(target, res); err != nil { 1082 return nil, err 1083 } 1084 return ret, nil 1085 // { 1086 // "description": "Lists operations that match the specified filter in the request. If the\nserver doesn't support this method, it returns `UNIMPLEMENTED`.\n\nNOTE: the `name` binding allows API services to override the binding\nto use different resource name schemes, such as `users/*/operations`. To\noverride the binding, API services can add a binding such as\n`\"/v1/{name=users/*}/operations\"` to their service configuration.\nFor backwards compatibility, the default name includes the operations\ncollection id, however overriding users must ensure the name binding\nis the parent resource, without the operations collection id.", 1087 // "flatPath": "v1beta1/operations", 1088 // "httpMethod": "GET", 1089 // "id": "speech.operations.list", 1090 // "parameterOrder": [], 1091 // "parameters": { 1092 // "filter": { 1093 // "description": "The standard list filter.", 1094 // "location": "query", 1095 // "type": "string" 1096 // }, 1097 // "name": { 1098 // "description": "The name of the operation's parent resource.", 1099 // "location": "query", 1100 // "type": "string" 1101 // }, 1102 // "pageSize": { 1103 // "description": "The standard list page size.", 1104 // "format": "int32", 1105 // "location": "query", 1106 // "type": "integer" 1107 // }, 1108 // "pageToken": { 1109 // "description": "The standard list page token.", 1110 // "location": "query", 1111 // "type": "string" 1112 // } 1113 // }, 1114 // "path": "v1beta1/operations", 1115 // "response": { 1116 // "$ref": "ListOperationsResponse" 1117 // }, 1118 // "scopes": [ 1119 // "https://www.googleapis.com/auth/cloud-platform" 1120 // ] 1121 // } 1122 1123 } 1124 1125 // Pages invokes f for each page of results. 1126 // A non-nil error returned from f will halt the iteration. 1127 // The provided context supersedes any context provided to the Context method. 1128 func (c *OperationsListCall) Pages(ctx context.Context, f func(*ListOperationsResponse) error) error { 1129 c.ctx_ = ctx 1130 defer c.PageToken(c.urlParams_.Get("pageToken")) // reset paging to original point 1131 for { 1132 x, err := c.Do() 1133 if err != nil { 1134 return err 1135 } 1136 if err := f(x); err != nil { 1137 return err 1138 } 1139 if x.NextPageToken == "" { 1140 return nil 1141 } 1142 c.PageToken(x.NextPageToken) 1143 } 1144 } 1145 1146 // method id "speech.speech.asyncrecognize": 1147 1148 type SpeechAsyncrecognizeCall struct { 1149 s *Service 1150 asyncrecognizerequest *AsyncRecognizeRequest 1151 urlParams_ gensupport.URLParams 1152 ctx_ context.Context 1153 header_ http.Header 1154 } 1155 1156 // Asyncrecognize: Performs asynchronous speech recognition: receive 1157 // results via 1158 // the 1159 // [google.longrunning.Operations] 1160 // (/speech/reference/rest/v1beta1/op 1161 // erations#Operation) 1162 // interface. Returns either an 1163 // `Operation.error` or an `Operation.response` which contains 1164 // an `AsyncRecognizeResponse` message. 1165 func (r *SpeechService) Asyncrecognize(asyncrecognizerequest *AsyncRecognizeRequest) *SpeechAsyncrecognizeCall { 1166 c := &SpeechAsyncrecognizeCall{s: r.s, urlParams_: make(gensupport.URLParams)} 1167 c.asyncrecognizerequest = asyncrecognizerequest 1168 return c 1169 } 1170 1171 // Fields allows partial responses to be retrieved. See 1172 // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse 1173 // for more information. 1174 func (c *SpeechAsyncrecognizeCall) Fields(s ...googleapi.Field) *SpeechAsyncrecognizeCall { 1175 c.urlParams_.Set("fields", googleapi.CombineFields(s)) 1176 return c 1177 } 1178 1179 // Context sets the context to be used in this call's Do method. Any 1180 // pending HTTP request will be aborted if the provided context is 1181 // canceled. 1182 func (c *SpeechAsyncrecognizeCall) Context(ctx context.Context) *SpeechAsyncrecognizeCall { 1183 c.ctx_ = ctx 1184 return c 1185 } 1186 1187 // Header returns an http.Header that can be modified by the caller to 1188 // add HTTP headers to the request. 1189 func (c *SpeechAsyncrecognizeCall) Header() http.Header { 1190 if c.header_ == nil { 1191 c.header_ = make(http.Header) 1192 } 1193 return c.header_ 1194 } 1195 1196 func (c *SpeechAsyncrecognizeCall) doRequest(alt string) (*http.Response, error) { 1197 reqHeaders := make(http.Header) 1198 reqHeaders.Set("x-goog-api-client", "gl-go/1.13.7 gdcl/20200203") 1199 for k, v := range c.header_ { 1200 reqHeaders[k] = v 1201 } 1202 reqHeaders.Set("User-Agent", c.s.userAgent()) 1203 var body io.Reader = nil 1204 body, err := googleapi.WithoutDataWrapper.JSONReader(c.asyncrecognizerequest) 1205 if err != nil { 1206 return nil, err 1207 } 1208 reqHeaders.Set("Content-Type", "application/json") 1209 c.urlParams_.Set("alt", alt) 1210 c.urlParams_.Set("prettyPrint", "false") 1211 urls := googleapi.ResolveRelative(c.s.BasePath, "v1beta1/speech:asyncrecognize") 1212 urls += "?" + c.urlParams_.Encode() 1213 req, err := http.NewRequest("POST", urls, body) 1214 if err != nil { 1215 return nil, err 1216 } 1217 req.Header = reqHeaders 1218 return gensupport.SendRequest(c.ctx_, c.s.client, req) 1219 } 1220 1221 // Do executes the "speech.speech.asyncrecognize" call. 1222 // Exactly one of *Operation or error will be non-nil. Any non-2xx 1223 // status code is an error. Response headers are in either 1224 // *Operation.ServerResponse.Header or (if a response was returned at 1225 // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified 1226 // to check whether the returned error was because 1227 // http.StatusNotModified was returned. 1228 func (c *SpeechAsyncrecognizeCall) Do(opts ...googleapi.CallOption) (*Operation, error) { 1229 gensupport.SetOptions(c.urlParams_, opts...) 1230 res, err := c.doRequest("json") 1231 if res != nil && res.StatusCode == http.StatusNotModified { 1232 if res.Body != nil { 1233 res.Body.Close() 1234 } 1235 return nil, &googleapi.Error{ 1236 Code: res.StatusCode, 1237 Header: res.Header, 1238 } 1239 } 1240 if err != nil { 1241 return nil, err 1242 } 1243 defer googleapi.CloseBody(res) 1244 if err := googleapi.CheckResponse(res); err != nil { 1245 return nil, err 1246 } 1247 ret := &Operation{ 1248 ServerResponse: googleapi.ServerResponse{ 1249 Header: res.Header, 1250 HTTPStatusCode: res.StatusCode, 1251 }, 1252 } 1253 target := &ret 1254 if err := gensupport.DecodeResponse(target, res); err != nil { 1255 return nil, err 1256 } 1257 return ret, nil 1258 // { 1259 // "description": "Performs asynchronous speech recognition: receive results via the\n[google.longrunning.Operations]\n(/speech/reference/rest/v1beta1/operations#Operation)\ninterface. Returns either an\n`Operation.error` or an `Operation.response` which contains\nan `AsyncRecognizeResponse` message.", 1260 // "flatPath": "v1beta1/speech:asyncrecognize", 1261 // "httpMethod": "POST", 1262 // "id": "speech.speech.asyncrecognize", 1263 // "parameterOrder": [], 1264 // "parameters": {}, 1265 // "path": "v1beta1/speech:asyncrecognize", 1266 // "request": { 1267 // "$ref": "AsyncRecognizeRequest" 1268 // }, 1269 // "response": { 1270 // "$ref": "Operation" 1271 // }, 1272 // "scopes": [ 1273 // "https://www.googleapis.com/auth/cloud-platform" 1274 // ] 1275 // } 1276 1277 } 1278 1279 // method id "speech.speech.syncrecognize": 1280 1281 type SpeechSyncrecognizeCall struct { 1282 s *Service 1283 syncrecognizerequest *SyncRecognizeRequest 1284 urlParams_ gensupport.URLParams 1285 ctx_ context.Context 1286 header_ http.Header 1287 } 1288 1289 // Syncrecognize: Performs synchronous speech recognition: receive 1290 // results after all audio 1291 // has been sent and processed. 1292 func (r *SpeechService) Syncrecognize(syncrecognizerequest *SyncRecognizeRequest) *SpeechSyncrecognizeCall { 1293 c := &SpeechSyncrecognizeCall{s: r.s, urlParams_: make(gensupport.URLParams)} 1294 c.syncrecognizerequest = syncrecognizerequest 1295 return c 1296 } 1297 1298 // Fields allows partial responses to be retrieved. See 1299 // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse 1300 // for more information. 1301 func (c *SpeechSyncrecognizeCall) Fields(s ...googleapi.Field) *SpeechSyncrecognizeCall { 1302 c.urlParams_.Set("fields", googleapi.CombineFields(s)) 1303 return c 1304 } 1305 1306 // Context sets the context to be used in this call's Do method. Any 1307 // pending HTTP request will be aborted if the provided context is 1308 // canceled. 1309 func (c *SpeechSyncrecognizeCall) Context(ctx context.Context) *SpeechSyncrecognizeCall { 1310 c.ctx_ = ctx 1311 return c 1312 } 1313 1314 // Header returns an http.Header that can be modified by the caller to 1315 // add HTTP headers to the request. 1316 func (c *SpeechSyncrecognizeCall) Header() http.Header { 1317 if c.header_ == nil { 1318 c.header_ = make(http.Header) 1319 } 1320 return c.header_ 1321 } 1322 1323 func (c *SpeechSyncrecognizeCall) doRequest(alt string) (*http.Response, error) { 1324 reqHeaders := make(http.Header) 1325 reqHeaders.Set("x-goog-api-client", "gl-go/1.13.7 gdcl/20200203") 1326 for k, v := range c.header_ { 1327 reqHeaders[k] = v 1328 } 1329 reqHeaders.Set("User-Agent", c.s.userAgent()) 1330 var body io.Reader = nil 1331 body, err := googleapi.WithoutDataWrapper.JSONReader(c.syncrecognizerequest) 1332 if err != nil { 1333 return nil, err 1334 } 1335 reqHeaders.Set("Content-Type", "application/json") 1336 c.urlParams_.Set("alt", alt) 1337 c.urlParams_.Set("prettyPrint", "false") 1338 urls := googleapi.ResolveRelative(c.s.BasePath, "v1beta1/speech:syncrecognize") 1339 urls += "?" + c.urlParams_.Encode() 1340 req, err := http.NewRequest("POST", urls, body) 1341 if err != nil { 1342 return nil, err 1343 } 1344 req.Header = reqHeaders 1345 return gensupport.SendRequest(c.ctx_, c.s.client, req) 1346 } 1347 1348 // Do executes the "speech.speech.syncrecognize" call. 1349 // Exactly one of *SyncRecognizeResponse or error will be non-nil. Any 1350 // non-2xx status code is an error. Response headers are in either 1351 // *SyncRecognizeResponse.ServerResponse.Header or (if a response was 1352 // returned at all) in error.(*googleapi.Error).Header. Use 1353 // googleapi.IsNotModified to check whether the returned error was 1354 // because http.StatusNotModified was returned. 1355 func (c *SpeechSyncrecognizeCall) Do(opts ...googleapi.CallOption) (*SyncRecognizeResponse, error) { 1356 gensupport.SetOptions(c.urlParams_, opts...) 1357 res, err := c.doRequest("json") 1358 if res != nil && res.StatusCode == http.StatusNotModified { 1359 if res.Body != nil { 1360 res.Body.Close() 1361 } 1362 return nil, &googleapi.Error{ 1363 Code: res.StatusCode, 1364 Header: res.Header, 1365 } 1366 } 1367 if err != nil { 1368 return nil, err 1369 } 1370 defer googleapi.CloseBody(res) 1371 if err := googleapi.CheckResponse(res); err != nil { 1372 return nil, err 1373 } 1374 ret := &SyncRecognizeResponse{ 1375 ServerResponse: googleapi.ServerResponse{ 1376 Header: res.Header, 1377 HTTPStatusCode: res.StatusCode, 1378 }, 1379 } 1380 target := &ret 1381 if err := gensupport.DecodeResponse(target, res); err != nil { 1382 return nil, err 1383 } 1384 return ret, nil 1385 // { 1386 // "description": "Performs synchronous speech recognition: receive results after all audio\nhas been sent and processed.", 1387 // "flatPath": "v1beta1/speech:syncrecognize", 1388 // "httpMethod": "POST", 1389 // "id": "speech.speech.syncrecognize", 1390 // "parameterOrder": [], 1391 // "parameters": {}, 1392 // "path": "v1beta1/speech:syncrecognize", 1393 // "request": { 1394 // "$ref": "SyncRecognizeRequest" 1395 // }, 1396 // "response": { 1397 // "$ref": "SyncRecognizeResponse" 1398 // }, 1399 // "scopes": [ 1400 // "https://www.googleapis.com/auth/cloud-platform" 1401 // ] 1402 // } 1403 1404 } 1405