Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

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