-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathmain.go
92 lines (76 loc) · 2.34 KB
/
main.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
// Copyright 2023 Deepgram SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT
package main
import (
"context"
"encoding/json"
"log"
"os"
prettyjson "github.com/hokaccha/go-prettyjson"
prerecorded "github.com/deepgram/deepgram-go-sdk/pkg/api/prerecorded/v1"
cfginterfaces "github.com/deepgram/deepgram-go-sdk/pkg/client/interfaces"
interfaces "github.com/deepgram/deepgram-go-sdk/pkg/client/interfaces"
client "github.com/deepgram/deepgram-go-sdk/pkg/client/prerecorded"
)
const (
filePath string = "./Bueller-Life-moves-pretty-fast.mp3"
)
func main() {
// init library
client.Init(client.InitLib{
LogLevel: client.LogLevelTrace, // LogLevelStandard / LogLevelFull / LogLevelTrace
})
// Go context
ctx := context.Background()
// set the Transcription options
options := interfaces.PreRecordedTranscriptionOptions{
Punctuate: true,
Diarize: true,
Language: "en-US",
// Utterances: true, // Commenting this out to demonstrate how to send a custom parameter
}
// create a Deepgram client
c := client.NewWithDefaults()
dg := prerecorded.New(c)
// example on how to send a custom header
headers := make(map[string][]string, 0)
headers["MY-CUSTOM-HEADER"] = []string{"CUSTOM"}
ctx = cfginterfaces.WithCustomHeaders(ctx, headers)
// example on how to send a custom parameter
params := make(map[string][]string, 0)
params["utterances"] = []string{"true"}
ctx = cfginterfaces.WithCustomParameters(ctx, params)
// send/process file to Deepgram
res, err := dg.FromFile(ctx, filePath, options)
if err != nil {
log.Printf("FromStream failed. Err: %v\n", err)
os.Exit(1)
}
data, err := json.Marshal(res)
if err != nil {
log.Printf("json.Marshal failed. Err: %v\n", err)
os.Exit(1)
}
// make the JSON pretty
prettyJson, err := prettyjson.Format(data)
if err != nil {
log.Printf("prettyjson.Marshal failed. Err: %v\n", err)
os.Exit(1)
}
log.Printf("\n\nResult:\n%s\n\n", prettyJson)
// dump example VTT
vtt, err := res.ToWebVTT()
if err != nil {
log.Printf("ToWebVTT failed. Err: %v\n", err)
os.Exit(1)
}
log.Printf("\n\n\nVTT:\n%s\n\n\n", vtt)
// dump example SRT
srt, err := res.ToSRT()
if err != nil {
log.Printf("ToSRT failed. Err: %v\n", err)
os.Exit(1)
}
log.Printf("\n\n\nSRT:\n%s\n\n\n", srt)
}