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 texttospeech provides access to the Cloud Text-to-Speech API. 8// 9// This package is DEPRECATED. Use package cloud.google.com/go/texttospeech/apiv1 instead. 10// 11// For product documentation, see: https://cloud.google.com/text-to-speech/ 12// 13// Creating a client 14// 15// Usage example: 16// 17// import "google.golang.org/api/texttospeech/v1beta1" 18// ... 19// ctx := context.Background() 20// texttospeechService, err := texttospeech.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// texttospeechService, err := texttospeech.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// texttospeechService, err := texttospeech.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token))) 38// 39// See https://godoc.org/google.golang.org/api/option/ for details on options. 40package texttospeech // import "google.golang.org/api/texttospeech/v1beta1" 41 42import ( 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 internaloption "google.golang.org/api/option/internaloption" 58 htransport "google.golang.org/api/transport/http" 59) 60 61// Always reference these packages, just in case the auto-generated code 62// below doesn't. 63var _ = bytes.NewBuffer 64var _ = strconv.Itoa 65var _ = fmt.Sprintf 66var _ = json.NewDecoder 67var _ = io.Copy 68var _ = url.Parse 69var _ = gensupport.MarshalJSON 70var _ = googleapi.Version 71var _ = errors.New 72var _ = strings.Replace 73var _ = context.Canceled 74var _ = internaloption.WithDefaultEndpoint 75 76const apiId = "texttospeech:v1beta1" 77const apiName = "texttospeech" 78const apiVersion = "v1beta1" 79const basePath = "https://texttospeech.googleapis.com/" 80 81// OAuth2 scopes used by this API. 82const ( 83 // View and manage your data across Google Cloud Platform services 84 CloudPlatformScope = "https://www.googleapis.com/auth/cloud-platform" 85) 86 87// NewService creates a new Service. 88func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) { 89 scopesOption := option.WithScopes( 90 "https://www.googleapis.com/auth/cloud-platform", 91 ) 92 // NOTE: prepend, so we don't override user-specified scopes. 93 opts = append([]option.ClientOption{scopesOption}, opts...) 94 opts = append(opts, internaloption.WithDefaultEndpoint(basePath)) 95 client, endpoint, err := htransport.NewClient(ctx, opts...) 96 if err != nil { 97 return nil, err 98 } 99 s, err := New(client) 100 if err != nil { 101 return nil, err 102 } 103 if endpoint != "" { 104 s.BasePath = endpoint 105 } 106 return s, nil 107} 108 109// New creates a new Service. It uses the provided http.Client for requests. 110// 111// Deprecated: please use NewService instead. 112// To provide a custom HTTP client, use option.WithHTTPClient. 113// If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead. 114func New(client *http.Client) (*Service, error) { 115 if client == nil { 116 return nil, errors.New("client is nil") 117 } 118 s := &Service{client: client, BasePath: basePath} 119 s.Text = NewTextService(s) 120 s.Voices = NewVoicesService(s) 121 return s, nil 122} 123 124type Service struct { 125 client *http.Client 126 BasePath string // API endpoint base URL 127 UserAgent string // optional additional User-Agent fragment 128 129 Text *TextService 130 131 Voices *VoicesService 132} 133 134func (s *Service) userAgent() string { 135 if s.UserAgent == "" { 136 return googleapi.UserAgent 137 } 138 return googleapi.UserAgent + " " + s.UserAgent 139} 140 141func NewTextService(s *Service) *TextService { 142 rs := &TextService{s: s} 143 return rs 144} 145 146type TextService struct { 147 s *Service 148} 149 150func NewVoicesService(s *Service) *VoicesService { 151 rs := &VoicesService{s: s} 152 return rs 153} 154 155type VoicesService struct { 156 s *Service 157} 158 159// AudioConfig: Description of audio data to be synthesized. 160type AudioConfig struct { 161 // AudioEncoding: Required. The format of the audio byte stream. 162 // 163 // Possible values: 164 // "AUDIO_ENCODING_UNSPECIFIED" - Not specified. Will return result 165 // google.rpc.Code.INVALID_ARGUMENT. 166 // "LINEAR16" - Uncompressed 16-bit signed little-endian samples 167 // (Linear PCM). 168 // Audio content returned as LINEAR16 also contains a WAV header. 169 // "MP3" - MP3 audio at 32kbps. 170 // "OGG_OPUS" - Opus encoded audio wrapped in an ogg container. The 171 // result will be a 172 // file which can be played natively on Android, and in browsers (at 173 // least 174 // Chrome and Firefox). The quality of the encoding is considerably 175 // higher 176 // than MP3 while using approximately the same bitrate. 177 AudioEncoding string `json:"audioEncoding,omitempty"` 178 179 // EffectsProfileId: Optional. Input only. An identifier which selects 180 // 'audio effects' profiles 181 // that are applied on (post synthesized) text to speech. Effects are 182 // applied 183 // on top of each other in the order they are given. 184 // See 185 // [audio 186 // profiles](https://cloud.google.com/text-to-speech/docs/audi 187 // o-profiles) for 188 // current supported profile ids. 189 EffectsProfileId []string `json:"effectsProfileId,omitempty"` 190 191 // Pitch: Optional. Input only. Speaking pitch, in the range [-20.0, 192 // 20.0]. 20 means 193 // increase 20 semitones from the original pitch. -20 means decrease 194 // 20 195 // semitones from the original pitch. 196 Pitch float64 `json:"pitch,omitempty"` 197 198 // SampleRateHertz: Optional. The synthesis sample rate (in hertz) for 199 // this audio. When this is 200 // specified in SynthesizeSpeechRequest, if this is different from the 201 // voice's 202 // natural sample rate, then the synthesizer will honor this request 203 // by 204 // converting to the desired sample rate (which might result in worse 205 // audio 206 // quality), unless the specified sample rate is not supported for 207 // the 208 // encoding chosen, in which case it will fail the request and 209 // return 210 // google.rpc.Code.INVALID_ARGUMENT. 211 SampleRateHertz int64 `json:"sampleRateHertz,omitempty"` 212 213 // SpeakingRate: Optional. Input only. Speaking rate/speed, in the range 214 // [0.25, 4.0]. 1.0 is 215 // the normal native speed supported by the specific voice. 2.0 is twice 216 // as 217 // fast, and 0.5 is half as fast. If unset(0.0), defaults to the native 218 // 1.0 219 // speed. Any other values < 0.25 or > 4.0 will return an error. 220 SpeakingRate float64 `json:"speakingRate,omitempty"` 221 222 // VolumeGainDb: Optional. Input only. Volume gain (in dB) of the normal 223 // native volume 224 // supported by the specific voice, in the range [-96.0, 16.0]. If 225 // unset, or 226 // set to a value of 0.0 (dB), will play at normal native signal 227 // amplitude. A 228 // value of -6.0 (dB) will play at approximately half the amplitude of 229 // the 230 // normal native signal amplitude. A value of +6.0 (dB) will play 231 // at 232 // approximately twice the amplitude of the normal native signal 233 // amplitude. 234 // Strongly recommend not to exceed +10 (dB) as there's usually no 235 // effective 236 // increase in loudness for any value greater than that. 237 VolumeGainDb float64 `json:"volumeGainDb,omitempty"` 238 239 // ForceSendFields is a list of field names (e.g. "AudioEncoding") to 240 // unconditionally include in API requests. By default, fields with 241 // empty values are omitted from API requests. However, any non-pointer, 242 // non-interface field appearing in ForceSendFields will be sent to the 243 // server regardless of whether the field is empty or not. This may be 244 // used to include empty fields in Patch requests. 245 ForceSendFields []string `json:"-"` 246 247 // NullFields is a list of field names (e.g. "AudioEncoding") to include 248 // in API requests with the JSON null value. By default, fields with 249 // empty values are omitted from API requests. However, any field with 250 // an empty value appearing in NullFields will be sent to the server as 251 // null. It is an error if a field in this list has a non-empty value. 252 // This may be used to include null fields in Patch requests. 253 NullFields []string `json:"-"` 254} 255 256func (s *AudioConfig) MarshalJSON() ([]byte, error) { 257 type NoMethod AudioConfig 258 raw := NoMethod(*s) 259 return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields) 260} 261 262func (s *AudioConfig) UnmarshalJSON(data []byte) error { 263 type NoMethod AudioConfig 264 var s1 struct { 265 Pitch gensupport.JSONFloat64 `json:"pitch"` 266 SpeakingRate gensupport.JSONFloat64 `json:"speakingRate"` 267 VolumeGainDb gensupport.JSONFloat64 `json:"volumeGainDb"` 268 *NoMethod 269 } 270 s1.NoMethod = (*NoMethod)(s) 271 if err := json.Unmarshal(data, &s1); err != nil { 272 return err 273 } 274 s.Pitch = float64(s1.Pitch) 275 s.SpeakingRate = float64(s1.SpeakingRate) 276 s.VolumeGainDb = float64(s1.VolumeGainDb) 277 return nil 278} 279 280// ListVoicesResponse: The message returned to the client by the 281// `ListVoices` method. 282type ListVoicesResponse struct { 283 // Voices: The list of voices. 284 Voices []*Voice `json:"voices,omitempty"` 285 286 // ServerResponse contains the HTTP response code and headers from the 287 // server. 288 googleapi.ServerResponse `json:"-"` 289 290 // ForceSendFields is a list of field names (e.g. "Voices") to 291 // unconditionally include in API requests. By default, fields with 292 // empty values are omitted from API requests. However, any non-pointer, 293 // non-interface field appearing in ForceSendFields will be sent to the 294 // server regardless of whether the field is empty or not. This may be 295 // used to include empty fields in Patch requests. 296 ForceSendFields []string `json:"-"` 297 298 // NullFields is a list of field names (e.g. "Voices") to include in API 299 // requests with the JSON null value. By default, fields with empty 300 // values are omitted from API requests. However, any field with an 301 // empty value appearing in NullFields will be sent to the server as 302 // null. It is an error if a field in this list has a non-empty value. 303 // This may be used to include null fields in Patch requests. 304 NullFields []string `json:"-"` 305} 306 307func (s *ListVoicesResponse) MarshalJSON() ([]byte, error) { 308 type NoMethod ListVoicesResponse 309 raw := NoMethod(*s) 310 return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields) 311} 312 313// SynthesisInput: Contains text input to be synthesized. Either `text` 314// or `ssml` must be 315// supplied. Supplying both or neither 316// returns 317// google.rpc.Code.INVALID_ARGUMENT. The input size is limited to 318// 5000 319// characters. 320type SynthesisInput struct { 321 // Ssml: The SSML document to be synthesized. The SSML document must be 322 // valid 323 // and well-formed. Otherwise the RPC will fail and 324 // return 325 // google.rpc.Code.INVALID_ARGUMENT. For more information, 326 // see 327 // [SSML](/speech/text-to-speech/docs/ssml). 328 Ssml string `json:"ssml,omitempty"` 329 330 // Text: The raw text to be synthesized. 331 Text string `json:"text,omitempty"` 332 333 // ForceSendFields is a list of field names (e.g. "Ssml") to 334 // unconditionally include in API requests. By default, fields with 335 // empty values are omitted from API requests. However, any non-pointer, 336 // non-interface field appearing in ForceSendFields will be sent to the 337 // server regardless of whether the field is empty or not. This may be 338 // used to include empty fields in Patch requests. 339 ForceSendFields []string `json:"-"` 340 341 // NullFields is a list of field names (e.g. "Ssml") to include in API 342 // requests with the JSON null value. By default, fields with empty 343 // values are omitted from API requests. However, any field with an 344 // empty value appearing in NullFields will be sent to the server as 345 // null. It is an error if a field in this list has a non-empty value. 346 // This may be used to include null fields in Patch requests. 347 NullFields []string `json:"-"` 348} 349 350func (s *SynthesisInput) MarshalJSON() ([]byte, error) { 351 type NoMethod SynthesisInput 352 raw := NoMethod(*s) 353 return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields) 354} 355 356// SynthesizeSpeechRequest: The top-level message sent by the client for 357// the `SynthesizeSpeech` method. 358type SynthesizeSpeechRequest struct { 359 // AudioConfig: Required. The configuration of the synthesized audio. 360 AudioConfig *AudioConfig `json:"audioConfig,omitempty"` 361 362 // Input: Required. The Synthesizer requires either plain text or SSML 363 // as input. 364 Input *SynthesisInput `json:"input,omitempty"` 365 366 // Voice: Required. The desired voice of the synthesized audio. 367 Voice *VoiceSelectionParams `json:"voice,omitempty"` 368 369 // ForceSendFields is a list of field names (e.g. "AudioConfig") to 370 // unconditionally include in API requests. By default, fields with 371 // empty values are omitted from API requests. However, any non-pointer, 372 // non-interface field appearing in ForceSendFields will be sent to the 373 // server regardless of whether the field is empty or not. This may be 374 // used to include empty fields in Patch requests. 375 ForceSendFields []string `json:"-"` 376 377 // NullFields is a list of field names (e.g. "AudioConfig") to include 378 // in API requests with the JSON null value. By default, fields with 379 // empty values are omitted from API requests. However, any field with 380 // an empty value appearing in NullFields will be sent to the server as 381 // null. It is an error if a field in this list has a non-empty value. 382 // This may be used to include null fields in Patch requests. 383 NullFields []string `json:"-"` 384} 385 386func (s *SynthesizeSpeechRequest) MarshalJSON() ([]byte, error) { 387 type NoMethod SynthesizeSpeechRequest 388 raw := NoMethod(*s) 389 return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields) 390} 391 392// SynthesizeSpeechResponse: The message returned to the client by the 393// `SynthesizeSpeech` method. 394type SynthesizeSpeechResponse struct { 395 // AudioContent: The audio data bytes encoded as specified in the 396 // request, including the 397 // header for encodings that are wrapped in containers (e.g. MP3, 398 // OGG_OPUS). 399 // For LINEAR16 audio, we include the WAV header. Note: as 400 // with all bytes fields, protobuffers use a pure binary 401 // representation, 402 // whereas JSON representations use base64. 403 AudioContent string `json:"audioContent,omitempty"` 404 405 // ServerResponse contains the HTTP response code and headers from the 406 // server. 407 googleapi.ServerResponse `json:"-"` 408 409 // ForceSendFields is a list of field names (e.g. "AudioContent") to 410 // unconditionally include in API requests. By default, fields with 411 // empty values are omitted from API requests. However, any non-pointer, 412 // non-interface field appearing in ForceSendFields will be sent to the 413 // server regardless of whether the field is empty or not. This may be 414 // used to include empty fields in Patch requests. 415 ForceSendFields []string `json:"-"` 416 417 // NullFields is a list of field names (e.g. "AudioContent") to include 418 // in API requests with the JSON null value. By default, fields with 419 // empty values are omitted from API requests. However, any field with 420 // an empty value appearing in NullFields will be sent to the server as 421 // null. It is an error if a field in this list has a non-empty value. 422 // This may be used to include null fields in Patch requests. 423 NullFields []string `json:"-"` 424} 425 426func (s *SynthesizeSpeechResponse) MarshalJSON() ([]byte, error) { 427 type NoMethod SynthesizeSpeechResponse 428 raw := NoMethod(*s) 429 return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields) 430} 431 432// Voice: Description of a voice supported by the TTS service. 433type Voice struct { 434 // LanguageCodes: The languages that this voice supports, expressed 435 // as 436 // [BCP-47](https://www.rfc-editor.org/rfc/bcp/bcp47.txt) language tags 437 // (e.g. 438 // "en-US", "es-419", "cmn-tw"). 439 LanguageCodes []string `json:"languageCodes,omitempty"` 440 441 // Name: The name of this voice. Each distinct voice has a unique name. 442 Name string `json:"name,omitempty"` 443 444 // NaturalSampleRateHertz: The natural sample rate (in hertz) for this 445 // voice. 446 NaturalSampleRateHertz int64 `json:"naturalSampleRateHertz,omitempty"` 447 448 // SsmlGender: The gender of this voice. 449 // 450 // Possible values: 451 // "SSML_VOICE_GENDER_UNSPECIFIED" - An unspecified gender. 452 // In VoiceSelectionParams, this means that the client doesn't care 453 // which 454 // gender the selected voice will have. In the Voice field 455 // of 456 // ListVoicesResponse, this may mean that the voice doesn't fit any of 457 // the 458 // other categories in this enum, or that the gender of the voice isn't 459 // known. 460 // "MALE" - A male voice. 461 // "FEMALE" - A female voice. 462 // "NEUTRAL" - A gender-neutral voice. 463 SsmlGender string `json:"ssmlGender,omitempty"` 464 465 // ForceSendFields is a list of field names (e.g. "LanguageCodes") to 466 // unconditionally include in API requests. By default, fields with 467 // empty values are omitted from API requests. However, any non-pointer, 468 // non-interface field appearing in ForceSendFields will be sent to the 469 // server regardless of whether the field is empty or not. This may be 470 // used to include empty fields in Patch requests. 471 ForceSendFields []string `json:"-"` 472 473 // NullFields is a list of field names (e.g. "LanguageCodes") to include 474 // in API requests with the JSON null value. By default, fields with 475 // empty values are omitted from API requests. However, any field with 476 // an empty value appearing in NullFields will be sent to the server as 477 // null. It is an error if a field in this list has a non-empty value. 478 // This may be used to include null fields in Patch requests. 479 NullFields []string `json:"-"` 480} 481 482func (s *Voice) MarshalJSON() ([]byte, error) { 483 type NoMethod Voice 484 raw := NoMethod(*s) 485 return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields) 486} 487 488// VoiceSelectionParams: Description of which voice to use for a 489// synthesis request. 490type VoiceSelectionParams struct { 491 // LanguageCode: Required. The language (and potentially also the 492 // region) of the voice expressed as 493 // a 494 // [BCP-47](https://www.rfc-editor.org/rfc/bcp/bcp47.txt) language tag, 495 // e.g. 496 // "en-US". This should not include a script tag (e.g. use 497 // "cmn-cn" rather than "cmn-Hant-cn"), because the script will be 498 // inferred 499 // from the input provided in the SynthesisInput. The TTS service 500 // will use this parameter to help choose an appropriate voice. Note 501 // that 502 // the TTS service may choose a voice with a slightly different language 503 // code 504 // than the one selected; it may substitute a different region 505 // (e.g. using en-US rather than en-CA if there isn't a Canadian 506 // voice 507 // available), or even a different language, e.g. using "nb" 508 // (Norwegian 509 // Bokmal) instead of "no" (Norwegian)". 510 LanguageCode string `json:"languageCode,omitempty"` 511 512 // Name: The name of the voice. If not set, the service will choose 513 // a 514 // voice based on the other parameters such as language_code and gender. 515 Name string `json:"name,omitempty"` 516 517 // SsmlGender: The preferred gender of the voice. If not set, the 518 // service will 519 // choose a voice based on the other parameters such as language_code 520 // and 521 // name. Note that this is only a preference, not requirement; if 522 // a 523 // voice of the appropriate gender is not available, the synthesizer 524 // should 525 // substitute a voice with a different gender rather than failing the 526 // request. 527 // 528 // Possible values: 529 // "SSML_VOICE_GENDER_UNSPECIFIED" - An unspecified gender. 530 // In VoiceSelectionParams, this means that the client doesn't care 531 // which 532 // gender the selected voice will have. In the Voice field 533 // of 534 // ListVoicesResponse, this may mean that the voice doesn't fit any of 535 // the 536 // other categories in this enum, or that the gender of the voice isn't 537 // known. 538 // "MALE" - A male voice. 539 // "FEMALE" - A female voice. 540 // "NEUTRAL" - A gender-neutral voice. 541 SsmlGender string `json:"ssmlGender,omitempty"` 542 543 // ForceSendFields is a list of field names (e.g. "LanguageCode") to 544 // unconditionally include in API requests. By default, fields with 545 // empty values are omitted from API requests. However, any non-pointer, 546 // non-interface field appearing in ForceSendFields will be sent to the 547 // server regardless of whether the field is empty or not. This may be 548 // used to include empty fields in Patch requests. 549 ForceSendFields []string `json:"-"` 550 551 // NullFields is a list of field names (e.g. "LanguageCode") to include 552 // in API requests with the JSON null value. By default, fields with 553 // empty values are omitted from API requests. However, any field with 554 // an empty value appearing in NullFields will be sent to the server as 555 // null. It is an error if a field in this list has a non-empty value. 556 // This may be used to include null fields in Patch requests. 557 NullFields []string `json:"-"` 558} 559 560func (s *VoiceSelectionParams) MarshalJSON() ([]byte, error) { 561 type NoMethod VoiceSelectionParams 562 raw := NoMethod(*s) 563 return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields) 564} 565 566// method id "texttospeech.text.synthesize": 567 568type TextSynthesizeCall struct { 569 s *Service 570 synthesizespeechrequest *SynthesizeSpeechRequest 571 urlParams_ gensupport.URLParams 572 ctx_ context.Context 573 header_ http.Header 574} 575 576// Synthesize: Synthesizes speech synchronously: receive results after 577// all text input 578// has been processed. 579func (r *TextService) Synthesize(synthesizespeechrequest *SynthesizeSpeechRequest) *TextSynthesizeCall { 580 c := &TextSynthesizeCall{s: r.s, urlParams_: make(gensupport.URLParams)} 581 c.synthesizespeechrequest = synthesizespeechrequest 582 return c 583} 584 585// Fields allows partial responses to be retrieved. See 586// https://developers.google.com/gdata/docs/2.0/basics#PartialResponse 587// for more information. 588func (c *TextSynthesizeCall) Fields(s ...googleapi.Field) *TextSynthesizeCall { 589 c.urlParams_.Set("fields", googleapi.CombineFields(s)) 590 return c 591} 592 593// Context sets the context to be used in this call's Do method. Any 594// pending HTTP request will be aborted if the provided context is 595// canceled. 596func (c *TextSynthesizeCall) Context(ctx context.Context) *TextSynthesizeCall { 597 c.ctx_ = ctx 598 return c 599} 600 601// Header returns an http.Header that can be modified by the caller to 602// add HTTP headers to the request. 603func (c *TextSynthesizeCall) Header() http.Header { 604 if c.header_ == nil { 605 c.header_ = make(http.Header) 606 } 607 return c.header_ 608} 609 610func (c *TextSynthesizeCall) doRequest(alt string) (*http.Response, error) { 611 reqHeaders := make(http.Header) 612 reqHeaders.Set("x-goog-api-client", "gl-go/"+gensupport.GoVersion()+" gdcl/20200302") 613 for k, v := range c.header_ { 614 reqHeaders[k] = v 615 } 616 reqHeaders.Set("User-Agent", c.s.userAgent()) 617 var body io.Reader = nil 618 body, err := googleapi.WithoutDataWrapper.JSONReader(c.synthesizespeechrequest) 619 if err != nil { 620 return nil, err 621 } 622 reqHeaders.Set("Content-Type", "application/json") 623 c.urlParams_.Set("alt", alt) 624 c.urlParams_.Set("prettyPrint", "false") 625 urls := googleapi.ResolveRelative(c.s.BasePath, "v1beta1/text:synthesize") 626 urls += "?" + c.urlParams_.Encode() 627 req, err := http.NewRequest("POST", urls, body) 628 if err != nil { 629 return nil, err 630 } 631 req.Header = reqHeaders 632 return gensupport.SendRequest(c.ctx_, c.s.client, req) 633} 634 635// Do executes the "texttospeech.text.synthesize" call. 636// Exactly one of *SynthesizeSpeechResponse or error will be non-nil. 637// Any non-2xx status code is an error. Response headers are in either 638// *SynthesizeSpeechResponse.ServerResponse.Header or (if a response was 639// returned at all) in error.(*googleapi.Error).Header. Use 640// googleapi.IsNotModified to check whether the returned error was 641// because http.StatusNotModified was returned. 642func (c *TextSynthesizeCall) Do(opts ...googleapi.CallOption) (*SynthesizeSpeechResponse, error) { 643 gensupport.SetOptions(c.urlParams_, opts...) 644 res, err := c.doRequest("json") 645 if res != nil && res.StatusCode == http.StatusNotModified { 646 if res.Body != nil { 647 res.Body.Close() 648 } 649 return nil, &googleapi.Error{ 650 Code: res.StatusCode, 651 Header: res.Header, 652 } 653 } 654 if err != nil { 655 return nil, err 656 } 657 defer googleapi.CloseBody(res) 658 if err := googleapi.CheckResponse(res); err != nil { 659 return nil, err 660 } 661 ret := &SynthesizeSpeechResponse{ 662 ServerResponse: googleapi.ServerResponse{ 663 Header: res.Header, 664 HTTPStatusCode: res.StatusCode, 665 }, 666 } 667 target := &ret 668 if err := gensupport.DecodeResponse(target, res); err != nil { 669 return nil, err 670 } 671 return ret, nil 672 // { 673 // "description": "Synthesizes speech synchronously: receive results after all text input\nhas been processed.", 674 // "flatPath": "v1beta1/text:synthesize", 675 // "httpMethod": "POST", 676 // "id": "texttospeech.text.synthesize", 677 // "parameterOrder": [], 678 // "parameters": {}, 679 // "path": "v1beta1/text:synthesize", 680 // "request": { 681 // "$ref": "SynthesizeSpeechRequest" 682 // }, 683 // "response": { 684 // "$ref": "SynthesizeSpeechResponse" 685 // }, 686 // "scopes": [ 687 // "https://www.googleapis.com/auth/cloud-platform" 688 // ] 689 // } 690 691} 692 693// method id "texttospeech.voices.list": 694 695type VoicesListCall struct { 696 s *Service 697 urlParams_ gensupport.URLParams 698 ifNoneMatch_ string 699 ctx_ context.Context 700 header_ http.Header 701} 702 703// List: Returns a list of Voice supported for synthesis. 704func (r *VoicesService) List() *VoicesListCall { 705 c := &VoicesListCall{s: r.s, urlParams_: make(gensupport.URLParams)} 706 return c 707} 708 709// LanguageCode sets the optional parameter "languageCode": 710// Recommended. 711// [BCP-47](https://www.rfc-editor.org/rfc/bcp/bcp47.txt) language tag. 712// If 713// specified, the ListVoices call will only return voices that can be 714// used to 715// synthesize this language_code. E.g. when specifying "en-NZ", you will 716// get 717// supported "en-*" voices; when specifying "no", you will get 718// supported 719// "no-*" (Norwegian) and "nb-*" (Norwegian Bokmal) voices; specifying 720// "zh" 721// will also get supported "cmn-*" voices; specifying "zh-hk" will also 722// get 723// supported "yue-*" voices. 724func (c *VoicesListCall) LanguageCode(languageCode string) *VoicesListCall { 725 c.urlParams_.Set("languageCode", languageCode) 726 return c 727} 728 729// Fields allows partial responses to be retrieved. See 730// https://developers.google.com/gdata/docs/2.0/basics#PartialResponse 731// for more information. 732func (c *VoicesListCall) Fields(s ...googleapi.Field) *VoicesListCall { 733 c.urlParams_.Set("fields", googleapi.CombineFields(s)) 734 return c 735} 736 737// IfNoneMatch sets the optional parameter which makes the operation 738// fail if the object's ETag matches the given value. This is useful for 739// getting updates only after the object has changed since the last 740// request. Use googleapi.IsNotModified to check whether the response 741// error from Do is the result of In-None-Match. 742func (c *VoicesListCall) IfNoneMatch(entityTag string) *VoicesListCall { 743 c.ifNoneMatch_ = entityTag 744 return c 745} 746 747// Context sets the context to be used in this call's Do method. Any 748// pending HTTP request will be aborted if the provided context is 749// canceled. 750func (c *VoicesListCall) Context(ctx context.Context) *VoicesListCall { 751 c.ctx_ = ctx 752 return c 753} 754 755// Header returns an http.Header that can be modified by the caller to 756// add HTTP headers to the request. 757func (c *VoicesListCall) Header() http.Header { 758 if c.header_ == nil { 759 c.header_ = make(http.Header) 760 } 761 return c.header_ 762} 763 764func (c *VoicesListCall) doRequest(alt string) (*http.Response, error) { 765 reqHeaders := make(http.Header) 766 reqHeaders.Set("x-goog-api-client", "gl-go/"+gensupport.GoVersion()+" gdcl/20200302") 767 for k, v := range c.header_ { 768 reqHeaders[k] = v 769 } 770 reqHeaders.Set("User-Agent", c.s.userAgent()) 771 if c.ifNoneMatch_ != "" { 772 reqHeaders.Set("If-None-Match", c.ifNoneMatch_) 773 } 774 var body io.Reader = nil 775 c.urlParams_.Set("alt", alt) 776 c.urlParams_.Set("prettyPrint", "false") 777 urls := googleapi.ResolveRelative(c.s.BasePath, "v1beta1/voices") 778 urls += "?" + c.urlParams_.Encode() 779 req, err := http.NewRequest("GET", urls, body) 780 if err != nil { 781 return nil, err 782 } 783 req.Header = reqHeaders 784 return gensupport.SendRequest(c.ctx_, c.s.client, req) 785} 786 787// Do executes the "texttospeech.voices.list" call. 788// Exactly one of *ListVoicesResponse or error will be non-nil. Any 789// non-2xx status code is an error. Response headers are in either 790// *ListVoicesResponse.ServerResponse.Header or (if a response was 791// returned at all) in error.(*googleapi.Error).Header. Use 792// googleapi.IsNotModified to check whether the returned error was 793// because http.StatusNotModified was returned. 794func (c *VoicesListCall) Do(opts ...googleapi.CallOption) (*ListVoicesResponse, error) { 795 gensupport.SetOptions(c.urlParams_, opts...) 796 res, err := c.doRequest("json") 797 if res != nil && res.StatusCode == http.StatusNotModified { 798 if res.Body != nil { 799 res.Body.Close() 800 } 801 return nil, &googleapi.Error{ 802 Code: res.StatusCode, 803 Header: res.Header, 804 } 805 } 806 if err != nil { 807 return nil, err 808 } 809 defer googleapi.CloseBody(res) 810 if err := googleapi.CheckResponse(res); err != nil { 811 return nil, err 812 } 813 ret := &ListVoicesResponse{ 814 ServerResponse: googleapi.ServerResponse{ 815 Header: res.Header, 816 HTTPStatusCode: res.StatusCode, 817 }, 818 } 819 target := &ret 820 if err := gensupport.DecodeResponse(target, res); err != nil { 821 return nil, err 822 } 823 return ret, nil 824 // { 825 // "description": "Returns a list of Voice supported for synthesis.", 826 // "flatPath": "v1beta1/voices", 827 // "httpMethod": "GET", 828 // "id": "texttospeech.voices.list", 829 // "parameterOrder": [], 830 // "parameters": { 831 // "languageCode": { 832 // "description": "Optional. Recommended.\n[BCP-47](https://www.rfc-editor.org/rfc/bcp/bcp47.txt) language tag. If\nspecified, the ListVoices call will only return voices that can be used to\nsynthesize this language_code. E.g. when specifying \"en-NZ\", you will get\nsupported \"en-*\" voices; when specifying \"no\", you will get supported\n\"no-*\" (Norwegian) and \"nb-*\" (Norwegian Bokmal) voices; specifying \"zh\"\nwill also get supported \"cmn-*\" voices; specifying \"zh-hk\" will also get\nsupported \"yue-*\" voices.", 833 // "location": "query", 834 // "type": "string" 835 // } 836 // }, 837 // "path": "v1beta1/voices", 838 // "response": { 839 // "$ref": "ListVoicesResponse" 840 // }, 841 // "scopes": [ 842 // "https://www.googleapis.com/auth/cloud-platform" 843 // ] 844 // } 845 846} 847