您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

765 行
27 KiB

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