-
Notifications
You must be signed in to change notification settings - Fork 12
/
custom_vocabulary.go
124 lines (100 loc) · 3.74 KB
/
custom_vocabulary.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package revai
import (
"context"
"fmt"
"net/http"
"time"
)
// CustomVocabularyService provides access to the custom vocabulary related functions
// in the Rev.ai API.
type CustomVocabularyService service
// CustomVocabulary represents a Rev.ai custom vocabulary
type CustomVocabulary struct {
ID string `json:"id"`
Status string `json:"status"`
CreatedOn time.Time `json:"created_on"`
CompletedOn time.Time `json:"completed_on"`
CallbackURL string `json:"callback_url"`
Failure string `json:"failure"`
FailureDetail string `json:"failure_detail"`
}
// CreateCustomVocabularyParams specifies the parameters to the
// CustomVocabularyService.Create method.
type CreateCustomVocabularyParams struct {
CustomVocabularies []Phrase `json:"custom_vocabularies"`
Metadata string `json:"metadata,omitempty"`
CallbackURL string `json:"callback_url,omitempty"`
}
type Phrase struct {
Phrases []string `json:"phrases"`
}
// Create submits a Custom Vocabulary for asynchronous processing.
// https://www.rev.ai/docs/streaming#operation/SubmitCustomVocabulary
func (s *CustomVocabularyService) Create(ctx context.Context, params *CreateCustomVocabularyParams) (*CustomVocabulary, error) {
urlPath := "/speechtotext/v1/vocabularies"
req, err := s.client.newRequest(http.MethodPost, urlPath, params)
if err != nil {
return nil, fmt.Errorf("failed creating request %w", err)
}
var vocabulary CustomVocabulary
if err := s.client.doJSON(ctx, req, &vocabulary); err != nil {
return nil, err
}
return &vocabulary, nil
}
// GetCustomVocabularyParams specifies the parameters to the
// CustomVocabularyService.Get method.
type GetCustomVocabularyParams struct {
ID string
}
// Get gets the custom vocabulary processing information
// https://www.rev.ai/docs/streaming#operation/GetCustomVocabulary
func (s *CustomVocabularyService) Get(ctx context.Context, params *GetCustomVocabularyParams) (*CustomVocabulary, error) {
urlPath := "/speechtotext/v1/vocabularies/" + params.ID
req, err := s.client.newRequest(http.MethodGet, urlPath, nil)
if err != nil {
return nil, fmt.Errorf("failed creating request %w", err)
}
var vocabulary CustomVocabulary
if err := s.client.doJSON(ctx, req, &vocabulary); err != nil {
return nil, err
}
return &vocabulary, nil
}
// ListCustomVocabularyParams specifies the parameters to the
// CustomVocabularyService.List method.
type ListCustomVocabularyParams struct {
Limit int `url:"limit,omitempty"`
}
// List gets a list of most recent custom vocabularies' processing information
// https://www.rev.ai/docs/streaming#operation/GetCustomVocabularies
func (s *CustomVocabularyService) List(ctx context.Context, params *ListCustomVocabularyParams) ([]*CustomVocabulary, error) {
urlPath := "/speechtotext/v1/vocabularies"
req, err := s.client.newRequest(http.MethodGet, urlPath, params)
if err != nil {
return nil, fmt.Errorf("failed creating request %w", err)
}
var vocabularies []*CustomVocabulary
if err := s.client.doJSON(ctx, req, &vocabularies); err != nil {
return nil, err
}
return vocabularies, nil
}
// DeleteCustomVocabularyParams specifies the parameters to the
// CustomVocabularyService.Delete method.
type DeleteCustomVocabularyParams struct {
ID string
}
// Delete deletes the custom vocabulary.
// https://www.rev.ai/docs/streaming#operation/DeleteCustomVocabulary
func (s *CustomVocabularyService) Delete(ctx context.Context, params *DeleteCustomVocabularyParams) error {
urlPath := "/speechtotext/v1/vocabularies/" + params.ID
req, err := s.client.newRequest(http.MethodDelete, urlPath, nil)
if err != nil {
return fmt.Errorf("failed creating request %w", err)
}
if err := s.client.doJSON(ctx, req, nil); err != nil {
return err
}
return nil
}