/
server_audio_transcription.go
63 lines (44 loc) · 1.09 KB
/
server_audio_transcription.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
package oai
import (
"net/http"
"github.com/adrianliechti/llama/pkg/provider"
)
func (s *Server) handleAudioTranscription(w http.ResponseWriter, r *http.Request) {
if err := r.ParseMultipartForm(32 << 20); err != nil {
writeError(w, http.StatusBadRequest, err)
return
}
model := r.FormValue("model")
transcriber, err := s.Transcriber(model)
if err != nil {
writeError(w, http.StatusBadRequest, err)
return
}
prompt := r.FormValue("prompt")
language := r.FormValue("language")
_ = prompt
_ = language
file, header, err := r.FormFile("file")
if err != nil {
writeError(w, http.StatusBadRequest, err)
return
}
defer file.Close()
input := provider.File{
Content: file,
Name: header.Filename,
}
options := &provider.TranscribeOptions{}
transcription, err := transcriber.Transcribe(r.Context(), input, options)
if err != nil {
writeError(w, http.StatusBadRequest, err)
return
}
result := Transcription{
Task: "transcribe",
Language: transcription.Language,
Duration: transcription.Duration,
Text: transcription.Content,
}
writeJson(w, result)
}