You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

842 lines
30 KiB

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