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