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