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