@@ -15,7 +15,7 @@ import (
15
15
func RegisterEndpoints (base string , mux * http.ServeMux , whisper * whisper.Whisper ) {
16
16
// Health: GET /v1/health
17
17
// returns an empty OK response
18
- mux .HandleFunc (joinPath (base , "health" ), func (w http.ResponseWriter , r * http.Request ) {
18
+ mux .HandleFunc (joinPath (base , "health" ), wrapLogging ( func (w http.ResponseWriter , r * http.Request ) {
19
19
defer r .Body .Close ()
20
20
21
21
switch r .Method {
@@ -24,14 +24,14 @@ func RegisterEndpoints(base string, mux *http.ServeMux, whisper *whisper.Whisper
24
24
default :
25
25
httpresponse .Error (w , http .StatusMethodNotAllowed )
26
26
}
27
- })
27
+ }))
28
28
29
29
// List Models: GET /v1/models
30
30
// returns available models
31
31
// Download Model: POST /v1/models?stream={bool}
32
32
// downloads a model from the server
33
33
// if stream is true then progress is streamed back to the client
34
- mux .HandleFunc (joinPath (base , "models" ), func (w http.ResponseWriter , r * http.Request ) {
34
+ mux .HandleFunc (joinPath (base , "models" ), wrapLogging ( func (w http.ResponseWriter , r * http.Request ) {
35
35
defer r .Body .Close ()
36
36
37
37
switch r .Method {
@@ -42,13 +42,13 @@ func RegisterEndpoints(base string, mux *http.ServeMux, whisper *whisper.Whisper
42
42
default :
43
43
httpresponse .Error (w , http .StatusMethodNotAllowed )
44
44
}
45
- })
45
+ }))
46
46
47
47
// Get: GET /v1/models/{id}
48
48
// returns an existing model
49
49
// Delete: DELETE /v1/models/{id}
50
50
// deletes an existing model
51
- mux .HandleFunc (joinPath (base , "models/{id}" ), func (w http.ResponseWriter , r * http.Request ) {
51
+ mux .HandleFunc (joinPath (base , "models/{id}" ), wrapLogging ( func (w http.ResponseWriter , r * http.Request ) {
52
52
defer r .Body .Close ()
53
53
54
54
id := r .PathValue ("id" )
@@ -60,12 +60,12 @@ func RegisterEndpoints(base string, mux *http.ServeMux, whisper *whisper.Whisper
60
60
default :
61
61
httpresponse .Error (w , http .StatusMethodNotAllowed )
62
62
}
63
- })
63
+ }))
64
64
65
65
// Translate: POST /v1/audio/translations
66
66
// Translates audio into english or another language - language parameter should be set to the
67
67
// destination language of the audio. Will default to english if not set.
68
- mux .HandleFunc (joinPath (base , "audio/translations" ), func (w http.ResponseWriter , r * http.Request ) {
68
+ mux .HandleFunc (joinPath (base , "audio/translations" ), wrapLogging ( func (w http.ResponseWriter , r * http.Request ) {
69
69
defer r .Body .Close ()
70
70
71
71
switch r .Method {
@@ -74,12 +74,12 @@ func RegisterEndpoints(base string, mux *http.ServeMux, whisper *whisper.Whisper
74
74
default :
75
75
httpresponse .Error (w , http .StatusMethodNotAllowed )
76
76
}
77
- })
77
+ }))
78
78
79
79
// Transcribe: POST /v1/audio/transcriptions
80
80
// Transcribes audio into the input language - language parameter should be set to the source
81
81
// language of the audio
82
- mux .HandleFunc (joinPath (base , "audio/transcriptions" ), func (w http.ResponseWriter , r * http.Request ) {
82
+ mux .HandleFunc (joinPath (base , "audio/transcriptions" ), wrapLogging ( func (w http.ResponseWriter , r * http.Request ) {
83
83
defer r .Body .Close ()
84
84
85
85
switch r .Method {
@@ -88,7 +88,21 @@ func RegisterEndpoints(base string, mux *http.ServeMux, whisper *whisper.Whisper
88
88
default :
89
89
httpresponse .Error (w , http .StatusMethodNotAllowed )
90
90
}
91
- })
91
+ }))
92
+
93
+ // Transcribe: POST /v1/audio/transcriptions/{model-id}
94
+ // Transcribes streamed media into the input language
95
+ mux .HandleFunc (joinPath (base , "audio/transcriptions/{model}" ), wrapLogging (func (w http.ResponseWriter , r * http.Request ) {
96
+ defer r .Body .Close ()
97
+
98
+ model := r .PathValue ("model" )
99
+ switch r .Method {
100
+ case http .MethodPost :
101
+ TranscribeStream (r .Context (), whisper , w , r , model )
102
+ default :
103
+ httpresponse .Error (w , http .StatusMethodNotAllowed )
104
+ }
105
+ }))
92
106
}
93
107
94
108
/////////////////////////////////////////////////////////////////////////////
0 commit comments