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.
 
 
 

1068 lines
38 KiB

  1. // Package speech provides access to the Cloud Speech API.
  2. //
  3. // See https://cloud.google.com/speech/
  4. //
  5. // Usage example:
  6. //
  7. // import "google.golang.org/api/speech/v1beta1"
  8. // ...
  9. // speechService, err := speech.New(oauthHttpClient)
  10. package speech // import "google.golang.org/api/speech/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 = "speech:v1beta1"
  41. const apiName = "speech"
  42. const apiVersion = "v1beta1"
  43. const basePath = "https://speech.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.Operations = NewOperationsService(s)
  55. s.Speech = NewSpeechService(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. Operations *OperationsService
  63. Speech *SpeechService
  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 NewOperationsService(s *Service) *OperationsService {
  72. rs := &OperationsService{s: s}
  73. return rs
  74. }
  75. type OperationsService struct {
  76. s *Service
  77. }
  78. func NewSpeechService(s *Service) *SpeechService {
  79. rs := &SpeechService{s: s}
  80. return rs
  81. }
  82. type SpeechService struct {
  83. s *Service
  84. }
  85. // AsyncRecognizeRequest: The top-level message sent by the client for
  86. // the `AsyncRecognize` method.
  87. type AsyncRecognizeRequest struct {
  88. // Audio: *Required* The audio data to be recognized.
  89. Audio *RecognitionAudio `json:"audio,omitempty"`
  90. // Config: *Required* Provides information to the recognizer that
  91. // specifies how to
  92. // process the request.
  93. Config *RecognitionConfig `json:"config,omitempty"`
  94. // ForceSendFields is a list of field names (e.g. "Audio") to
  95. // unconditionally include in API requests. By default, fields with
  96. // empty values are omitted from API requests. However, any non-pointer,
  97. // non-interface field appearing in ForceSendFields will be sent to the
  98. // server regardless of whether the field is empty or not. This may be
  99. // used to include empty fields in Patch requests.
  100. ForceSendFields []string `json:"-"`
  101. // NullFields is a list of field names (e.g. "Audio") to include in API
  102. // requests with the JSON null value. By default, fields with empty
  103. // values are omitted from API requests. However, any field with an
  104. // empty value appearing in NullFields will be sent to the server as
  105. // null. It is an error if a field in this list has a non-empty value.
  106. // This may be used to include null fields in Patch requests.
  107. NullFields []string `json:"-"`
  108. }
  109. func (s *AsyncRecognizeRequest) MarshalJSON() ([]byte, error) {
  110. type NoMethod AsyncRecognizeRequest
  111. raw := NoMethod(*s)
  112. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  113. }
  114. // Operation: This resource represents a long-running operation that is
  115. // the result of a
  116. // network API call.
  117. type Operation struct {
  118. // Done: If the value is `false`, it means the operation is still in
  119. // progress.
  120. // If `true`, the operation is completed, and either `error` or
  121. // `response` is
  122. // available.
  123. Done bool `json:"done,omitempty"`
  124. // Error: The error result of the operation in case of failure or
  125. // cancellation.
  126. Error *Status `json:"error,omitempty"`
  127. // Metadata: Service-specific metadata associated with the operation.
  128. // It typically
  129. // contains progress information and common metadata such as create
  130. // time.
  131. // Some services might not provide such metadata. Any method that
  132. // returns a
  133. // long-running operation should document the metadata type, if any.
  134. Metadata googleapi.RawMessage `json:"metadata,omitempty"`
  135. // Name: The server-assigned name, which is only unique within the same
  136. // service that
  137. // originally returns it. If you use the default HTTP mapping,
  138. // the
  139. // `name` should have the format of `operations/some/unique/name`.
  140. Name string `json:"name,omitempty"`
  141. // Response: The normal response of the operation in case of success.
  142. // If the original
  143. // method returns no data on success, such as `Delete`, the response
  144. // is
  145. // `google.protobuf.Empty`. If the original method is
  146. // standard
  147. // `Get`/`Create`/`Update`, the response should be the resource. For
  148. // other
  149. // methods, the response should have the type `XxxResponse`, where
  150. // `Xxx`
  151. // is the original method name. For example, if the original method
  152. // name
  153. // is `TakeSnapshot()`, the inferred response type
  154. // is
  155. // `TakeSnapshotResponse`.
  156. Response googleapi.RawMessage `json:"response,omitempty"`
  157. // ServerResponse contains the HTTP response code and headers from the
  158. // server.
  159. googleapi.ServerResponse `json:"-"`
  160. // ForceSendFields is a list of field names (e.g. "Done") to
  161. // unconditionally include in API requests. By default, fields with
  162. // empty values are omitted from API requests. However, any non-pointer,
  163. // non-interface field appearing in ForceSendFields will be sent to the
  164. // server regardless of whether the field is empty or not. This may be
  165. // used to include empty fields in Patch requests.
  166. ForceSendFields []string `json:"-"`
  167. // NullFields is a list of field names (e.g. "Done") to include in API
  168. // requests with the JSON null value. By default, fields with empty
  169. // values are omitted from API requests. However, any field with an
  170. // empty value appearing in NullFields will be sent to the server as
  171. // null. It is an error if a field in this list has a non-empty value.
  172. // This may be used to include null fields in Patch requests.
  173. NullFields []string `json:"-"`
  174. }
  175. func (s *Operation) MarshalJSON() ([]byte, error) {
  176. type NoMethod Operation
  177. raw := NoMethod(*s)
  178. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  179. }
  180. // RecognitionAudio: Contains audio data in the encoding specified in
  181. // the `RecognitionConfig`.
  182. // Either `content` or `uri` must be supplied. Supplying both or
  183. // neither
  184. // returns google.rpc.Code.INVALID_ARGUMENT. See
  185. // [audio limits](https://cloud.google.com/speech/limits#content).
  186. type RecognitionAudio struct {
  187. // Content: The audio data bytes encoded as specified
  188. // in
  189. // `RecognitionConfig`. Note: as with all bytes fields, protobuffers use
  190. // a
  191. // pure binary representation, whereas JSON representations use base64.
  192. Content string `json:"content,omitempty"`
  193. // Uri: URI that points to a file that contains audio data bytes as
  194. // specified in
  195. // `RecognitionConfig`. Currently, only Google Cloud Storage URIs
  196. // are
  197. // supported, which must be specified in the following
  198. // format:
  199. // `gs://bucket_name/object_name` (other URI formats
  200. // return
  201. // google.rpc.Code.INVALID_ARGUMENT). For more information, see
  202. // [Request URIs](https://cloud.google.com/storage/docs/reference-uris).
  203. Uri string `json:"uri,omitempty"`
  204. // ForceSendFields is a list of field names (e.g. "Content") to
  205. // unconditionally include in API requests. By default, fields with
  206. // empty values are omitted from API requests. However, any non-pointer,
  207. // non-interface field appearing in ForceSendFields will be sent to the
  208. // server regardless of whether the field is empty or not. This may be
  209. // used to include empty fields in Patch requests.
  210. ForceSendFields []string `json:"-"`
  211. // NullFields is a list of field names (e.g. "Content") to include in
  212. // API requests with the JSON null value. By default, fields with empty
  213. // values are omitted from API requests. However, any field with an
  214. // empty value appearing in NullFields will be sent to the server as
  215. // null. It is an error if a field in this list has a non-empty value.
  216. // This may be used to include null fields in Patch requests.
  217. NullFields []string `json:"-"`
  218. }
  219. func (s *RecognitionAudio) MarshalJSON() ([]byte, error) {
  220. type NoMethod RecognitionAudio
  221. raw := NoMethod(*s)
  222. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  223. }
  224. // RecognitionConfig: Provides information to the recognizer that
  225. // specifies how to process the
  226. // request.
  227. type RecognitionConfig struct {
  228. // Encoding: *Required* Encoding of audio data sent in all
  229. // `RecognitionAudio` messages.
  230. //
  231. // Possible values:
  232. // "ENCODING_UNSPECIFIED" - Not specified. Will return result
  233. // google.rpc.Code.INVALID_ARGUMENT.
  234. // "LINEAR16" - Uncompressed 16-bit signed little-endian samples
  235. // (Linear PCM).
  236. // This is the only encoding that may be used by `AsyncRecognize`.
  237. // "FLAC" - This is the recommended encoding for `SyncRecognize`
  238. // and
  239. // `StreamingRecognize` because it uses lossless compression;
  240. // therefore
  241. // recognition accuracy is not compromised by a lossy codec.
  242. //
  243. // The stream FLAC (Free Lossless Audio Codec) encoding is specified
  244. // at:
  245. // http://flac.sourceforge.net/documentation.html.
  246. // 16-bit and 24-bit samples are supported.
  247. // Not all fields in STREAMINFO are supported.
  248. // "MULAW" - 8-bit samples that compand 14-bit audio samples using
  249. // G.711 PCMU/mu-law.
  250. // "AMR" - Adaptive Multi-Rate Narrowband codec. `sample_rate` must be
  251. // 8000 Hz.
  252. // "AMR_WB" - Adaptive Multi-Rate Wideband codec. `sample_rate` must
  253. // be 16000 Hz.
  254. Encoding string `json:"encoding,omitempty"`
  255. // LanguageCode: *Optional* The language of the supplied audio as a
  256. // BCP-47 language tag.
  257. // Example: "en-GB" https://www.rfc-editor.org/rfc/bcp/bcp47.txt
  258. // If omitted, defaults to "en-US". See
  259. // [Language
  260. // Support](https://cloud.google.com/speech/docs/languages)
  261. // for a list of the currently supported language codes.
  262. LanguageCode string `json:"languageCode,omitempty"`
  263. // MaxAlternatives: *Optional* Maximum number of recognition hypotheses
  264. // to be returned.
  265. // Specifically, the maximum number of `SpeechRecognitionAlternative`
  266. // messages
  267. // within each `SpeechRecognitionResult`.
  268. // The server may return fewer than `max_alternatives`.
  269. // Valid values are `0`-`30`. A value of `0` or `1` will return a
  270. // maximum of
  271. // one. If omitted, will return a maximum of one.
  272. MaxAlternatives int64 `json:"maxAlternatives,omitempty"`
  273. // ProfanityFilter: *Optional* If set to `true`, the server will attempt
  274. // to filter out
  275. // profanities, replacing all but the initial character in each filtered
  276. // word
  277. // with asterisks, e.g. "f***". If set to `false` or omitted,
  278. // profanities
  279. // won't be filtered out.
  280. ProfanityFilter bool `json:"profanityFilter,omitempty"`
  281. // SampleRate: *Required* Sample rate in Hertz of the audio data sent in
  282. // all
  283. // `RecognitionAudio` messages. Valid values are: 8000-48000.
  284. // 16000 is optimal. For best results, set the sampling rate of the
  285. // audio
  286. // source to 16000 Hz. If that's not possible, use the native sample
  287. // rate of
  288. // the audio source (instead of re-sampling).
  289. SampleRate int64 `json:"sampleRate,omitempty"`
  290. // SpeechContext: *Optional* A means to provide context to assist the
  291. // speech recognition.
  292. SpeechContext *SpeechContext `json:"speechContext,omitempty"`
  293. // ForceSendFields is a list of field names (e.g. "Encoding") 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. "Encoding") to include in
  301. // API requests with the JSON null value. By default, fields with empty
  302. // values are omitted from API requests. However, any field with an
  303. // empty value appearing in NullFields will be sent to the server as
  304. // null. It is an error if a field in this list has a non-empty value.
  305. // This may be used to include null fields in Patch requests.
  306. NullFields []string `json:"-"`
  307. }
  308. func (s *RecognitionConfig) MarshalJSON() ([]byte, error) {
  309. type NoMethod RecognitionConfig
  310. raw := NoMethod(*s)
  311. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  312. }
  313. // SpeechContext: Provides "hints" to the speech recognizer to favor
  314. // specific words and phrases
  315. // in the results.
  316. type SpeechContext struct {
  317. // Phrases: *Optional* A list of strings containing words and phrases
  318. // "hints" so that
  319. // the speech recognition is more likely to recognize them. This can be
  320. // used
  321. // to improve the accuracy for specific words and phrases, for example,
  322. // if
  323. // specific commands are typically spoken by the user. This can also be
  324. // used
  325. // to add additional words to the vocabulary of the recognizer.
  326. // See
  327. // [usage limits](https://cloud.google.com/speech/limits#content).
  328. Phrases []string `json:"phrases,omitempty"`
  329. // ForceSendFields is a list of field names (e.g. "Phrases") to
  330. // unconditionally include in API requests. By default, fields with
  331. // empty values are omitted from API requests. However, any non-pointer,
  332. // non-interface field appearing in ForceSendFields will be sent to the
  333. // server regardless of whether the field is empty or not. This may be
  334. // used to include empty fields in Patch requests.
  335. ForceSendFields []string `json:"-"`
  336. // NullFields is a list of field names (e.g. "Phrases") to include in
  337. // API requests with the JSON null value. By default, fields with empty
  338. // values are omitted from API requests. However, any field with an
  339. // empty value appearing in NullFields will be sent to the server as
  340. // null. It is an error if a field in this list has a non-empty value.
  341. // This may be used to include null fields in Patch requests.
  342. NullFields []string `json:"-"`
  343. }
  344. func (s *SpeechContext) MarshalJSON() ([]byte, error) {
  345. type NoMethod SpeechContext
  346. raw := NoMethod(*s)
  347. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  348. }
  349. // SpeechRecognitionAlternative: Alternative hypotheses (a.k.a. n-best
  350. // list).
  351. type SpeechRecognitionAlternative struct {
  352. // Confidence: *Output-only* The confidence estimate between 0.0 and
  353. // 1.0. A higher number
  354. // indicates an estimated greater likelihood that the recognized words
  355. // are
  356. // correct. This field is typically provided only for the top
  357. // hypothesis, and
  358. // only for `is_final=true` results. Clients should not rely on
  359. // the
  360. // `confidence` field as it is not guaranteed to be accurate, or even
  361. // set, in
  362. // any of the results.
  363. // The default of 0.0 is a sentinel value indicating `confidence` was
  364. // not set.
  365. Confidence float64 `json:"confidence,omitempty"`
  366. // Transcript: *Output-only* Transcript text representing the words that
  367. // the user spoke.
  368. Transcript string `json:"transcript,omitempty"`
  369. // ForceSendFields is a list of field names (e.g. "Confidence") to
  370. // unconditionally include in API requests. By default, fields with
  371. // empty values are omitted from API requests. However, any non-pointer,
  372. // non-interface field appearing in ForceSendFields will be sent to the
  373. // server regardless of whether the field is empty or not. This may be
  374. // used to include empty fields in Patch requests.
  375. ForceSendFields []string `json:"-"`
  376. // NullFields is a list of field names (e.g. "Confidence") to include in
  377. // API requests with the JSON null value. By default, fields with empty
  378. // values are omitted from API requests. However, any field with an
  379. // empty value appearing in NullFields will be sent to the server as
  380. // null. It is an error if a field in this list has a non-empty value.
  381. // This may be used to include null fields in Patch requests.
  382. NullFields []string `json:"-"`
  383. }
  384. func (s *SpeechRecognitionAlternative) MarshalJSON() ([]byte, error) {
  385. type NoMethod SpeechRecognitionAlternative
  386. raw := NoMethod(*s)
  387. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  388. }
  389. func (s *SpeechRecognitionAlternative) UnmarshalJSON(data []byte) error {
  390. type NoMethod SpeechRecognitionAlternative
  391. var s1 struct {
  392. Confidence gensupport.JSONFloat64 `json:"confidence"`
  393. *NoMethod
  394. }
  395. s1.NoMethod = (*NoMethod)(s)
  396. if err := json.Unmarshal(data, &s1); err != nil {
  397. return err
  398. }
  399. s.Confidence = float64(s1.Confidence)
  400. return nil
  401. }
  402. // SpeechRecognitionResult: A speech recognition result corresponding to
  403. // a portion of the audio.
  404. type SpeechRecognitionResult struct {
  405. // Alternatives: *Output-only* May contain one or more recognition
  406. // hypotheses (up to the
  407. // maximum specified in `max_alternatives`).
  408. Alternatives []*SpeechRecognitionAlternative `json:"alternatives,omitempty"`
  409. // ForceSendFields is a list of field names (e.g. "Alternatives") to
  410. // unconditionally include in API requests. By default, fields with
  411. // empty values are omitted from API requests. However, any non-pointer,
  412. // non-interface field appearing in ForceSendFields will be sent to the
  413. // server regardless of whether the field is empty or not. This may be
  414. // used to include empty fields in Patch requests.
  415. ForceSendFields []string `json:"-"`
  416. // NullFields is a list of field names (e.g. "Alternatives") to include
  417. // in API requests with the JSON null value. By default, fields with
  418. // empty values are omitted from API requests. However, any field with
  419. // an empty value appearing in NullFields will be sent to the server as
  420. // null. It is an error if a field in this list has a non-empty value.
  421. // This may be used to include null fields in Patch requests.
  422. NullFields []string `json:"-"`
  423. }
  424. func (s *SpeechRecognitionResult) MarshalJSON() ([]byte, error) {
  425. type NoMethod SpeechRecognitionResult
  426. raw := NoMethod(*s)
  427. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  428. }
  429. // Status: The `Status` type defines a logical error model that is
  430. // suitable for different
  431. // programming environments, including REST APIs and RPC APIs. It is
  432. // used by
  433. // [gRPC](https://github.com/grpc). The error model is designed to
  434. // be:
  435. //
  436. // - Simple to use and understand for most users
  437. // - Flexible enough to meet unexpected needs
  438. //
  439. // # Overview
  440. //
  441. // The `Status` message contains three pieces of data: error code, error
  442. // message,
  443. // and error details. The error code should be an enum value
  444. // of
  445. // google.rpc.Code, but it may accept additional error codes if needed.
  446. // The
  447. // error message should be a developer-facing English message that
  448. // helps
  449. // developers *understand* and *resolve* the error. If a localized
  450. // user-facing
  451. // error message is needed, put the localized message in the error
  452. // details or
  453. // localize it in the client. The optional error details may contain
  454. // arbitrary
  455. // information about the error. There is a predefined set of error
  456. // detail types
  457. // in the package `google.rpc` that can be used for common error
  458. // conditions.
  459. //
  460. // # Language mapping
  461. //
  462. // The `Status` message is the logical representation of the error
  463. // model, but it
  464. // is not necessarily the actual wire format. When the `Status` message
  465. // is
  466. // exposed in different client libraries and different wire protocols,
  467. // it can be
  468. // mapped differently. For example, it will likely be mapped to some
  469. // exceptions
  470. // in Java, but more likely mapped to some error codes in C.
  471. //
  472. // # Other uses
  473. //
  474. // The error model and the `Status` message can be used in a variety
  475. // of
  476. // environments, either with or without APIs, to provide a
  477. // consistent developer experience across different
  478. // environments.
  479. //
  480. // Example uses of this error model include:
  481. //
  482. // - Partial errors. If a service needs to return partial errors to the
  483. // client,
  484. // it may embed the `Status` in the normal response to indicate the
  485. // partial
  486. // errors.
  487. //
  488. // - Workflow errors. A typical workflow has multiple steps. Each step
  489. // may
  490. // have a `Status` message for error reporting.
  491. //
  492. // - Batch operations. If a client uses batch request and batch
  493. // response, the
  494. // `Status` message should be used directly inside batch response,
  495. // one for
  496. // each error sub-response.
  497. //
  498. // - Asynchronous operations. If an API call embeds asynchronous
  499. // operation
  500. // results in its response, the status of those operations should
  501. // be
  502. // represented directly using the `Status` message.
  503. //
  504. // - Logging. If some API errors are stored in logs, the message
  505. // `Status` could
  506. // be used directly after any stripping needed for security/privacy
  507. // reasons.
  508. type Status struct {
  509. // Code: The status code, which should be an enum value of
  510. // google.rpc.Code.
  511. Code int64 `json:"code,omitempty"`
  512. // Details: A list of messages that carry the error details. There is a
  513. // common set of
  514. // message types for APIs to use.
  515. Details []googleapi.RawMessage `json:"details,omitempty"`
  516. // Message: A developer-facing error message, which should be in
  517. // English. Any
  518. // user-facing error message should be localized and sent in
  519. // the
  520. // google.rpc.Status.details field, or localized by the client.
  521. Message string `json:"message,omitempty"`
  522. // ForceSendFields is a list of field names (e.g. "Code") to
  523. // unconditionally include in API requests. By default, fields with
  524. // empty values are omitted from API requests. However, any non-pointer,
  525. // non-interface field appearing in ForceSendFields will be sent to the
  526. // server regardless of whether the field is empty or not. This may be
  527. // used to include empty fields in Patch requests.
  528. ForceSendFields []string `json:"-"`
  529. // NullFields is a list of field names (e.g. "Code") to include in API
  530. // requests with the JSON null value. By default, fields with empty
  531. // values are omitted from API requests. However, any field with an
  532. // empty value appearing in NullFields will be sent to the server as
  533. // null. It is an error if a field in this list has a non-empty value.
  534. // This may be used to include null fields in Patch requests.
  535. NullFields []string `json:"-"`
  536. }
  537. func (s *Status) MarshalJSON() ([]byte, error) {
  538. type NoMethod Status
  539. raw := NoMethod(*s)
  540. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  541. }
  542. // SyncRecognizeRequest: The top-level message sent by the client for
  543. // the `SyncRecognize` method.
  544. type SyncRecognizeRequest struct {
  545. // Audio: *Required* The audio data to be recognized.
  546. Audio *RecognitionAudio `json:"audio,omitempty"`
  547. // Config: *Required* Provides information to the recognizer that
  548. // specifies how to
  549. // process the request.
  550. Config *RecognitionConfig `json:"config,omitempty"`
  551. // ForceSendFields is a list of field names (e.g. "Audio") to
  552. // unconditionally include in API requests. By default, fields with
  553. // empty values are omitted from API requests. However, any non-pointer,
  554. // non-interface field appearing in ForceSendFields will be sent to the
  555. // server regardless of whether the field is empty or not. This may be
  556. // used to include empty fields in Patch requests.
  557. ForceSendFields []string `json:"-"`
  558. // NullFields is a list of field names (e.g. "Audio") to include in API
  559. // requests with the JSON null value. By default, fields with empty
  560. // values are omitted from API requests. However, any field with an
  561. // empty value appearing in NullFields will be sent to the server as
  562. // null. It is an error if a field in this list has a non-empty value.
  563. // This may be used to include null fields in Patch requests.
  564. NullFields []string `json:"-"`
  565. }
  566. func (s *SyncRecognizeRequest) MarshalJSON() ([]byte, error) {
  567. type NoMethod SyncRecognizeRequest
  568. raw := NoMethod(*s)
  569. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  570. }
  571. // SyncRecognizeResponse: The only message returned to the client by
  572. // `SyncRecognize`. method. It
  573. // contains the result as zero or more sequential
  574. // `SpeechRecognitionResult`
  575. // messages.
  576. type SyncRecognizeResponse struct {
  577. // Results: *Output-only* Sequential list of transcription results
  578. // corresponding to
  579. // sequential portions of audio.
  580. Results []*SpeechRecognitionResult `json:"results,omitempty"`
  581. // ServerResponse contains the HTTP response code and headers from the
  582. // server.
  583. googleapi.ServerResponse `json:"-"`
  584. // ForceSendFields is a list of field names (e.g. "Results") to
  585. // unconditionally include in API requests. By default, fields with
  586. // empty values are omitted from API requests. However, any non-pointer,
  587. // non-interface field appearing in ForceSendFields will be sent to the
  588. // server regardless of whether the field is empty or not. This may be
  589. // used to include empty fields in Patch requests.
  590. ForceSendFields []string `json:"-"`
  591. // NullFields is a list of field names (e.g. "Results") to include in
  592. // API requests with the JSON null value. By default, fields with empty
  593. // values are omitted from API requests. However, any field with an
  594. // empty value appearing in NullFields will be sent to the server as
  595. // null. It is an error if a field in this list has a non-empty value.
  596. // This may be used to include null fields in Patch requests.
  597. NullFields []string `json:"-"`
  598. }
  599. func (s *SyncRecognizeResponse) MarshalJSON() ([]byte, error) {
  600. type NoMethod SyncRecognizeResponse
  601. raw := NoMethod(*s)
  602. return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
  603. }
  604. // method id "speech.operations.get":
  605. type OperationsGetCall struct {
  606. s *Service
  607. name string
  608. urlParams_ gensupport.URLParams
  609. ifNoneMatch_ string
  610. ctx_ context.Context
  611. header_ http.Header
  612. }
  613. // Get: Gets the latest state of a long-running operation. Clients can
  614. // use this
  615. // method to poll the operation result at intervals as recommended by
  616. // the API
  617. // service.
  618. func (r *OperationsService) Get(name string) *OperationsGetCall {
  619. c := &OperationsGetCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  620. c.name = name
  621. return c
  622. }
  623. // Fields allows partial responses to be retrieved. See
  624. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  625. // for more information.
  626. func (c *OperationsGetCall) Fields(s ...googleapi.Field) *OperationsGetCall {
  627. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  628. return c
  629. }
  630. // IfNoneMatch sets the optional parameter which makes the operation
  631. // fail if the object's ETag matches the given value. This is useful for
  632. // getting updates only after the object has changed since the last
  633. // request. Use googleapi.IsNotModified to check whether the response
  634. // error from Do is the result of In-None-Match.
  635. func (c *OperationsGetCall) IfNoneMatch(entityTag string) *OperationsGetCall {
  636. c.ifNoneMatch_ = entityTag
  637. return c
  638. }
  639. // Context sets the context to be used in this call's Do method. Any
  640. // pending HTTP request will be aborted if the provided context is
  641. // canceled.
  642. func (c *OperationsGetCall) Context(ctx context.Context) *OperationsGetCall {
  643. c.ctx_ = ctx
  644. return c
  645. }
  646. // Header returns an http.Header that can be modified by the caller to
  647. // add HTTP headers to the request.
  648. func (c *OperationsGetCall) Header() http.Header {
  649. if c.header_ == nil {
  650. c.header_ = make(http.Header)
  651. }
  652. return c.header_
  653. }
  654. func (c *OperationsGetCall) doRequest(alt string) (*http.Response, error) {
  655. reqHeaders := make(http.Header)
  656. for k, v := range c.header_ {
  657. reqHeaders[k] = v
  658. }
  659. reqHeaders.Set("User-Agent", c.s.userAgent())
  660. if c.ifNoneMatch_ != "" {
  661. reqHeaders.Set("If-None-Match", c.ifNoneMatch_)
  662. }
  663. var body io.Reader = nil
  664. c.urlParams_.Set("alt", alt)
  665. urls := googleapi.ResolveRelative(c.s.BasePath, "v1beta1/operations/{+name}")
  666. urls += "?" + c.urlParams_.Encode()
  667. req, _ := http.NewRequest("GET", urls, body)
  668. req.Header = reqHeaders
  669. googleapi.Expand(req.URL, map[string]string{
  670. "name": c.name,
  671. })
  672. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  673. }
  674. // Do executes the "speech.operations.get" call.
  675. // Exactly one of *Operation or error will be non-nil. Any non-2xx
  676. // status code is an error. Response headers are in either
  677. // *Operation.ServerResponse.Header or (if a response was returned at
  678. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  679. // to check whether the returned error was because
  680. // http.StatusNotModified was returned.
  681. func (c *OperationsGetCall) Do(opts ...googleapi.CallOption) (*Operation, error) {
  682. gensupport.SetOptions(c.urlParams_, opts...)
  683. res, err := c.doRequest("json")
  684. if res != nil && res.StatusCode == http.StatusNotModified {
  685. if res.Body != nil {
  686. res.Body.Close()
  687. }
  688. return nil, &googleapi.Error{
  689. Code: res.StatusCode,
  690. Header: res.Header,
  691. }
  692. }
  693. if err != nil {
  694. return nil, err
  695. }
  696. defer googleapi.CloseBody(res)
  697. if err := googleapi.CheckResponse(res); err != nil {
  698. return nil, err
  699. }
  700. ret := &Operation{
  701. ServerResponse: googleapi.ServerResponse{
  702. Header: res.Header,
  703. HTTPStatusCode: res.StatusCode,
  704. },
  705. }
  706. target := &ret
  707. if err := gensupport.DecodeResponse(target, res); err != nil {
  708. return nil, err
  709. }
  710. return ret, nil
  711. // {
  712. // "description": "Gets the latest state of a long-running operation. Clients can use this\nmethod to poll the operation result at intervals as recommended by the API\nservice.",
  713. // "flatPath": "v1beta1/operations/{operationsId}",
  714. // "httpMethod": "GET",
  715. // "id": "speech.operations.get",
  716. // "parameterOrder": [
  717. // "name"
  718. // ],
  719. // "parameters": {
  720. // "name": {
  721. // "description": "The name of the operation resource.",
  722. // "location": "path",
  723. // "pattern": "^[^/]+$",
  724. // "required": true,
  725. // "type": "string"
  726. // }
  727. // },
  728. // "path": "v1beta1/operations/{+name}",
  729. // "response": {
  730. // "$ref": "Operation"
  731. // },
  732. // "scopes": [
  733. // "https://www.googleapis.com/auth/cloud-platform"
  734. // ]
  735. // }
  736. }
  737. // method id "speech.speech.asyncrecognize":
  738. type SpeechAsyncrecognizeCall struct {
  739. s *Service
  740. asyncrecognizerequest *AsyncRecognizeRequest
  741. urlParams_ gensupport.URLParams
  742. ctx_ context.Context
  743. header_ http.Header
  744. }
  745. // Asyncrecognize: Performs asynchronous speech recognition: receive
  746. // results via
  747. // the
  748. // [google.longrunning.Operations]
  749. // (/speech/reference/rest/v1beta1/op
  750. // erations#Operation)
  751. // interface. Returns either an
  752. // `Operation.error` or an `Operation.response` which contains
  753. // an `AsyncRecognizeResponse` message.
  754. func (r *SpeechService) Asyncrecognize(asyncrecognizerequest *AsyncRecognizeRequest) *SpeechAsyncrecognizeCall {
  755. c := &SpeechAsyncrecognizeCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  756. c.asyncrecognizerequest = asyncrecognizerequest
  757. return c
  758. }
  759. // Fields allows partial responses to be retrieved. See
  760. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  761. // for more information.
  762. func (c *SpeechAsyncrecognizeCall) Fields(s ...googleapi.Field) *SpeechAsyncrecognizeCall {
  763. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  764. return c
  765. }
  766. // Context sets the context to be used in this call's Do method. Any
  767. // pending HTTP request will be aborted if the provided context is
  768. // canceled.
  769. func (c *SpeechAsyncrecognizeCall) Context(ctx context.Context) *SpeechAsyncrecognizeCall {
  770. c.ctx_ = ctx
  771. return c
  772. }
  773. // Header returns an http.Header that can be modified by the caller to
  774. // add HTTP headers to the request.
  775. func (c *SpeechAsyncrecognizeCall) Header() http.Header {
  776. if c.header_ == nil {
  777. c.header_ = make(http.Header)
  778. }
  779. return c.header_
  780. }
  781. func (c *SpeechAsyncrecognizeCall) doRequest(alt string) (*http.Response, error) {
  782. reqHeaders := make(http.Header)
  783. for k, v := range c.header_ {
  784. reqHeaders[k] = v
  785. }
  786. reqHeaders.Set("User-Agent", c.s.userAgent())
  787. var body io.Reader = nil
  788. body, err := googleapi.WithoutDataWrapper.JSONReader(c.asyncrecognizerequest)
  789. if err != nil {
  790. return nil, err
  791. }
  792. reqHeaders.Set("Content-Type", "application/json")
  793. c.urlParams_.Set("alt", alt)
  794. urls := googleapi.ResolveRelative(c.s.BasePath, "v1beta1/speech:asyncrecognize")
  795. urls += "?" + c.urlParams_.Encode()
  796. req, _ := http.NewRequest("POST", urls, body)
  797. req.Header = reqHeaders
  798. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  799. }
  800. // Do executes the "speech.speech.asyncrecognize" call.
  801. // Exactly one of *Operation or error will be non-nil. Any non-2xx
  802. // status code is an error. Response headers are in either
  803. // *Operation.ServerResponse.Header or (if a response was returned at
  804. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  805. // to check whether the returned error was because
  806. // http.StatusNotModified was returned.
  807. func (c *SpeechAsyncrecognizeCall) Do(opts ...googleapi.CallOption) (*Operation, error) {
  808. gensupport.SetOptions(c.urlParams_, opts...)
  809. res, err := c.doRequest("json")
  810. if res != nil && res.StatusCode == http.StatusNotModified {
  811. if res.Body != nil {
  812. res.Body.Close()
  813. }
  814. return nil, &googleapi.Error{
  815. Code: res.StatusCode,
  816. Header: res.Header,
  817. }
  818. }
  819. if err != nil {
  820. return nil, err
  821. }
  822. defer googleapi.CloseBody(res)
  823. if err := googleapi.CheckResponse(res); err != nil {
  824. return nil, err
  825. }
  826. ret := &Operation{
  827. ServerResponse: googleapi.ServerResponse{
  828. Header: res.Header,
  829. HTTPStatusCode: res.StatusCode,
  830. },
  831. }
  832. target := &ret
  833. if err := gensupport.DecodeResponse(target, res); err != nil {
  834. return nil, err
  835. }
  836. return ret, nil
  837. // {
  838. // "description": "Performs asynchronous speech recognition: receive results via the\n[google.longrunning.Operations]\n(/speech/reference/rest/v1beta1/operations#Operation)\ninterface. Returns either an\n`Operation.error` or an `Operation.response` which contains\nan `AsyncRecognizeResponse` message.",
  839. // "flatPath": "v1beta1/speech:asyncrecognize",
  840. // "httpMethod": "POST",
  841. // "id": "speech.speech.asyncrecognize",
  842. // "parameterOrder": [],
  843. // "parameters": {},
  844. // "path": "v1beta1/speech:asyncrecognize",
  845. // "request": {
  846. // "$ref": "AsyncRecognizeRequest"
  847. // },
  848. // "response": {
  849. // "$ref": "Operation"
  850. // },
  851. // "scopes": [
  852. // "https://www.googleapis.com/auth/cloud-platform"
  853. // ]
  854. // }
  855. }
  856. // method id "speech.speech.syncrecognize":
  857. type SpeechSyncrecognizeCall struct {
  858. s *Service
  859. syncrecognizerequest *SyncRecognizeRequest
  860. urlParams_ gensupport.URLParams
  861. ctx_ context.Context
  862. header_ http.Header
  863. }
  864. // Syncrecognize: Performs synchronous speech recognition: receive
  865. // results after all audio
  866. // has been sent and processed.
  867. func (r *SpeechService) Syncrecognize(syncrecognizerequest *SyncRecognizeRequest) *SpeechSyncrecognizeCall {
  868. c := &SpeechSyncrecognizeCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  869. c.syncrecognizerequest = syncrecognizerequest
  870. return c
  871. }
  872. // Fields allows partial responses to be retrieved. See
  873. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  874. // for more information.
  875. func (c *SpeechSyncrecognizeCall) Fields(s ...googleapi.Field) *SpeechSyncrecognizeCall {
  876. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  877. return c
  878. }
  879. // Context sets the context to be used in this call's Do method. Any
  880. // pending HTTP request will be aborted if the provided context is
  881. // canceled.
  882. func (c *SpeechSyncrecognizeCall) Context(ctx context.Context) *SpeechSyncrecognizeCall {
  883. c.ctx_ = ctx
  884. return c
  885. }
  886. // Header returns an http.Header that can be modified by the caller to
  887. // add HTTP headers to the request.
  888. func (c *SpeechSyncrecognizeCall) Header() http.Header {
  889. if c.header_ == nil {
  890. c.header_ = make(http.Header)
  891. }
  892. return c.header_
  893. }
  894. func (c *SpeechSyncrecognizeCall) doRequest(alt string) (*http.Response, error) {
  895. reqHeaders := make(http.Header)
  896. for k, v := range c.header_ {
  897. reqHeaders[k] = v
  898. }
  899. reqHeaders.Set("User-Agent", c.s.userAgent())
  900. var body io.Reader = nil
  901. body, err := googleapi.WithoutDataWrapper.JSONReader(c.syncrecognizerequest)
  902. if err != nil {
  903. return nil, err
  904. }
  905. reqHeaders.Set("Content-Type", "application/json")
  906. c.urlParams_.Set("alt", alt)
  907. urls := googleapi.ResolveRelative(c.s.BasePath, "v1beta1/speech:syncrecognize")
  908. urls += "?" + c.urlParams_.Encode()
  909. req, _ := http.NewRequest("POST", urls, body)
  910. req.Header = reqHeaders
  911. return gensupport.SendRequest(c.ctx_, c.s.client, req)
  912. }
  913. // Do executes the "speech.speech.syncrecognize" call.
  914. // Exactly one of *SyncRecognizeResponse or error will be non-nil. Any
  915. // non-2xx status code is an error. Response headers are in either
  916. // *SyncRecognizeResponse.ServerResponse.Header or (if a response was
  917. // returned at all) in error.(*googleapi.Error).Header. Use
  918. // googleapi.IsNotModified to check whether the returned error was
  919. // because http.StatusNotModified was returned.
  920. func (c *SpeechSyncrecognizeCall) Do(opts ...googleapi.CallOption) (*SyncRecognizeResponse, error) {
  921. gensupport.SetOptions(c.urlParams_, opts...)
  922. res, err := c.doRequest("json")
  923. if res != nil && res.StatusCode == http.StatusNotModified {
  924. if res.Body != nil {
  925. res.Body.Close()
  926. }
  927. return nil, &googleapi.Error{
  928. Code: res.StatusCode,
  929. Header: res.Header,
  930. }
  931. }
  932. if err != nil {
  933. return nil, err
  934. }
  935. defer googleapi.CloseBody(res)
  936. if err := googleapi.CheckResponse(res); err != nil {
  937. return nil, err
  938. }
  939. ret := &SyncRecognizeResponse{
  940. ServerResponse: googleapi.ServerResponse{
  941. Header: res.Header,
  942. HTTPStatusCode: res.StatusCode,
  943. },
  944. }
  945. target := &ret
  946. if err := gensupport.DecodeResponse(target, res); err != nil {
  947. return nil, err
  948. }
  949. return ret, nil
  950. // {
  951. // "description": "Performs synchronous speech recognition: receive results after all audio\nhas been sent and processed.",
  952. // "flatPath": "v1beta1/speech:syncrecognize",
  953. // "httpMethod": "POST",
  954. // "id": "speech.speech.syncrecognize",
  955. // "parameterOrder": [],
  956. // "parameters": {},
  957. // "path": "v1beta1/speech:syncrecognize",
  958. // "request": {
  959. // "$ref": "SyncRecognizeRequest"
  960. // },
  961. // "response": {
  962. // "$ref": "SyncRecognizeResponse"
  963. // },
  964. // "scopes": [
  965. // "https://www.googleapis.com/auth/cloud-platform"
  966. // ]
  967. // }
  968. }