/
speech.clj
105 lines (93 loc) · 3.4 KB
/
speech.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
(ns happygapi.speech.speech
"Cloud Speech-to-Text API: speech.
Converts audio to text by applying powerful neural network models.
See: https://cloud.google.com/speech-to-text/docs/quickstart-protocolapi/reference/rest/v1/speech"
(:require [cheshire.core :as json]
[clj-http.client :as http]
[happy.util :as util]))
(defn longrunningrecognize$
"https://cloud.google.com/speech-to-text/docs/quickstart-protocolapi/reference/rest/v1/speech/longrunningrecognize
Required parameters: none
Optional parameters: none
Body:
{:config {:encoding string,
:maxAlternatives integer,
:enableAutomaticPunctuation boolean,
:enableWordTimeOffsets boolean,
:enableSeparateRecognitionPerChannel boolean,
:speechContexts [SpeechContext],
:sampleRateHertz integer,
:languageCode string,
:profanityFilter boolean,
:audioChannelCount integer,
:metadata RecognitionMetadata,
:useEnhanced boolean,
:diarizationConfig SpeakerDiarizationConfig,
:model string},
:audio {:content string, :uri string}}
Performs asynchronous speech recognition: receive results via the
google.longrunning.Operations interface. Returns either an
`Operation.error` or an `Operation.response` which contains
a `LongRunningRecognizeResponse` message.
For more information on asynchronous speech recognition, see the
[how-to](https://cloud.google.com/speech-to-text/docs/async-recognize)."
{:scopes ["https://www.googleapis.com/auth/cloud-platform"]}
[auth parameters body]
{:pre [(util/has-keys? parameters #{})]}
(util/get-response
(http/post
(util/get-url
"https://speech.googleapis.com/"
"v1/speech:longrunningrecognize"
#{}
parameters)
(merge-with
merge
{:content-type :json,
:body (json/generate-string body),
:throw-exceptions false,
:query-params parameters,
:accept :json,
:as :json}
auth))))
(defn recognize$
"https://cloud.google.com/speech-to-text/docs/quickstart-protocolapi/reference/rest/v1/speech/recognize
Required parameters: none
Optional parameters: none
Body:
{:config {:encoding string,
:maxAlternatives integer,
:enableAutomaticPunctuation boolean,
:enableWordTimeOffsets boolean,
:enableSeparateRecognitionPerChannel boolean,
:speechContexts [SpeechContext],
:sampleRateHertz integer,
:languageCode string,
:profanityFilter boolean,
:audioChannelCount integer,
:metadata RecognitionMetadata,
:useEnhanced boolean,
:diarizationConfig SpeakerDiarizationConfig,
:model string},
:audio {:content string, :uri string}}
Performs synchronous speech recognition: receive results after all audio
has been sent and processed."
{:scopes ["https://www.googleapis.com/auth/cloud-platform"]}
[auth parameters body]
{:pre [(util/has-keys? parameters #{})]}
(util/get-response
(http/post
(util/get-url
"https://speech.googleapis.com/"
"v1/speech:recognize"
#{}
parameters)
(merge-with
merge
{:content-type :json,
:body (json/generate-string body),
:throw-exceptions false,
:query-params parameters,
:accept :json,
:as :json}
auth))))