-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathdictation.go
51 lines (42 loc) · 1.04 KB
/
dictation.go
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
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
package witai
import (
"encoding/json"
"io"
"net/http"
)
type DictationRequest struct {
File io.Reader
ContentType string
}
type DictationToken struct {
End int `json:"end"`
Start int `json:"start"`
Token string `json:"token"`
}
type DictationSpeech struct {
Confidence float64 `json:"confidence"`
Tokens []DictationToken `json:"tokens"`
}
type DictationResponse struct {
Speech DictationSpeech `json:"speech"`
Text string `json:"text"`
Type string `json:"type"`
}
// Dictation - Returns the text transcription from an audio file or stream.
func (c *Client) Dictation(req DictationRequest) (*DictationResponse, error) {
resp, err := c.request(http.MethodPost, "/dictation", req.ContentType, req.File)
if err != nil {
return nil, err
}
defer resp.Close()
var msgResp *DictationResponse
decoder := json.NewDecoder(resp)
for {
err := decoder.Decode(&msgResp)
if err != nil {
break
}
}
return msgResp, err
}