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