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