From 2772d73f8758b8273c6d312621c3ca1f1369a618 Mon Sep 17 00:00:00 2001 From: dvonthenen Date: Wed, 6 Dec 2023 08:06:19 -0800 Subject: [PATCH] Fix Example Comments --- examples/manage/invitations/main.go | 40 +++++++++++++++++---------- examples/manage/members/main.go | 4 +-- examples/manage/scopes/main.go | 4 +-- examples/prerecorded/file/main.go | 28 ++++++++++--------- examples/prerecorded/stream/main.go | 23 +++++++-------- examples/prerecorded/url/main.go | 7 +++-- examples/streaming/microphone/main.go | 9 +++--- examples/streaming/replay/main.go | 7 +++-- 8 files changed, 70 insertions(+), 52 deletions(-) diff --git a/examples/manage/invitations/main.go b/examples/manage/invitations/main.go index 3c25e942..d332a25d 100644 --- a/examples/manage/invitations/main.go +++ b/examples/manage/invitations/main.go @@ -47,10 +47,14 @@ func main() { os.Exit(1) } - for _, item := range respGet.Invites { - id := item.Email - scope := item.Scope - log.Printf("ListInvitations() - ID: %s, Scope: %s\n", id, scope) + if len(respGet.Invites) == 0 { + log.Printf("ListInvitations() - No invitations found\n") + } else { + for _, item := range respGet.Invites { + id := item.Email + scope := item.Scope + log.Printf("ListInvitations() - ID: %s, Scope: %s\n", id, scope) + } } // send invite @@ -62,7 +66,7 @@ func main() { log.Printf("SendInvitation failed. Err: %v\n", err) os.Exit(1) } - log.Printf("SendInvitation() - Name: %s\n", respMessage.Message) + log.Printf("SendInvitation() - Result: %s\n", respMessage.Message) // list invitations respGet, err = mgClient.ListInvitations(ctx, projectId) @@ -71,10 +75,14 @@ func main() { os.Exit(1) } - for _, item := range respGet.Invites { - id := item.Email - scope := item.Scope - log.Printf("ListInvitations() - ID: %s, Scope: %s\n", id, scope) + if len(respGet.Invites) == 0 { + log.Printf("ListInvitations() - No invitations found\n") + } else { + for _, item := range respGet.Invites { + id := item.Email + scope := item.Scope + log.Printf("ListInvitations() - ID: %s, Scope: %s\n", id, scope) + } } // delete project @@ -83,7 +91,7 @@ func main() { log.Printf("DeleteInvitation failed. Err: %v\n", err) os.Exit(1) } - log.Printf("DeleteInvitation() - Name: %s\n", respMessage.Message) + log.Printf("DeleteInvitation() - Result: %s\n", respMessage.Message) // list invitations respGet, err = mgClient.ListInvitations(ctx, projectId) @@ -92,10 +100,14 @@ func main() { os.Exit(1) } - for _, item := range respGet.Invites { - id := item.Email - scope := item.Scope - log.Printf("ListInvitations() - ID: %s, Scope: %s\n", id, scope) + if len(respGet.Invites) == 0 { + log.Printf("ListInvitations() - No invitations found\n") + } else { + for _, item := range respGet.Invites { + id := item.Email + scope := item.Scope + log.Printf("ListInvitations() - ID: %s, Scope: %s\n", id, scope) + } } // There isnt an API call to add a member to a project. So will leave this commented out as an example diff --git a/examples/manage/members/main.go b/examples/manage/members/main.go index e3a91ff6..2f140f20 100644 --- a/examples/manage/members/main.go +++ b/examples/manage/members/main.go @@ -43,7 +43,7 @@ func main() { break } - // list invitations + // list members respGet, err := mgClient.ListMembers(ctx, projectId) if err != nil { log.Printf("ListMembers failed. Err: %v\n", err) @@ -76,7 +76,7 @@ func main() { } log.Printf("RemoveMember() - Name: %s\n", respMessage.Message) - // list invitations + // list members respGet, err = mgClient.ListMembers(ctx, projectId) if err != nil { log.Printf("ListMembers failed. Err: %v\n", err) diff --git a/examples/manage/scopes/main.go b/examples/manage/scopes/main.go index 0cb03d83..17e8f36e 100644 --- a/examples/manage/scopes/main.go +++ b/examples/manage/scopes/main.go @@ -44,7 +44,7 @@ func main() { break } - // list invitations + // list members respGet, err := mgClient.ListMembers(ctx, projectId) if err != nil { log.Printf("ListMembers failed. Err: %v\n", err) @@ -94,7 +94,7 @@ func main() { } log.Printf("UpdateMemberScopes() - Name: %s\n", respMessage.Message) - // list invitations + // list members respGet, err = mgClient.ListMembers(ctx, projectId) if err != nil { log.Printf("ListMembers failed. Err: %v\n", err) diff --git a/examples/prerecorded/file/main.go b/examples/prerecorded/file/main.go index 07df0067..3126c029 100644 --- a/examples/prerecorded/file/main.go +++ b/examples/prerecorded/file/main.go @@ -27,24 +27,23 @@ func main() { LogLevel: client.LogLevelTrace, // LogLevelStandard / LogLevelFull / LogLevelTrace }) - // context + // Go context ctx := context.Background() - //client + // set the Transcription options + options := interfaces.PreRecordedTranscriptionOptions{ + Punctuate: true, + Diarize: true, + Language: "en-US", + Utterances: true, + } + + // create a Deepgram client c := client.NewWithDefaults() dg := prerecorded.New(c) - // send file stream - res, err := dg.FromFile( - ctx, - filePath, - interfaces.PreRecordedTranscriptionOptions{ - Punctuate: true, - Diarize: true, - Language: "en-US", - Utterances: true, - }, - ) + // 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) @@ -56,6 +55,7 @@ func main() { os.Exit(1) } + // make the JSON pretty prettyJson, err := prettyjson.Format(data) if err != nil { log.Printf("prettyjson.Marshal failed. Err: %v\n", err) @@ -63,6 +63,7 @@ func main() { } 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) @@ -70,6 +71,7 @@ func main() { } 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) diff --git a/examples/prerecorded/stream/main.go b/examples/prerecorded/stream/main.go index 948d3eac..8b1f1bc2 100644 --- a/examples/prerecorded/stream/main.go +++ b/examples/prerecorded/stream/main.go @@ -30,11 +30,19 @@ func main() { // context ctx := context.Background() + // set the Transcription options + options := interfaces.PreRecordedTranscriptionOptions{ + Punctuate: true, + Diarize: true, + Language: "en-US", + Utterances: true, + } + //client c := client.NewWithDefaults() dg := prerecorded.New(c) - // send file stream + // open file sream file, err := os.Open(filePath) if err != nil { log.Printf("os.Open(%s) failed. Err: %v\n", filePath, err) @@ -42,16 +50,8 @@ func main() { } defer file.Close() - res, err := dg.FromStream( - ctx, - file, - interfaces.PreRecordedTranscriptionOptions{ - Punctuate: true, - Diarize: true, - Language: "en-US", - Utterances: true, - }, - ) + // send stream to Deepgram + res, err := dg.FromStream(ctx, file, options) if err != nil { log.Printf("FromStream failed. Err: %v\n", err) os.Exit(1) @@ -63,6 +63,7 @@ func main() { os.Exit(1) } + // make the JSON pretty prettyJson, err := prettyjson.Format(data) if err != nil { log.Printf("prettyjson.Marshal failed. Err: %v\n", err) diff --git a/examples/prerecorded/url/main.go b/examples/prerecorded/url/main.go index 36c31d6a..e8ee0686 100644 --- a/examples/prerecorded/url/main.go +++ b/examples/prerecorded/url/main.go @@ -28,7 +28,7 @@ func main() { // context ctx := context.Background() - // options + // send stream to Deepgram options := interfaces.PreRecordedTranscriptionOptions{ Punctuate: true, Diarize: true, @@ -37,11 +37,11 @@ func main() { Redact: []string{"pci", "ssn"}, } - //client + // create a Deepgram client c := client.NewWithDefaults() dg := prerecorded.New(c) - // send stream + // send the URL to Deepgram res, err := dg.FromURL(ctx, url, options) if err != nil { log.Printf("FromURL failed. Err: %v\n", err) @@ -54,6 +54,7 @@ func main() { os.Exit(1) } + // make the JSON pretty prettyJson, err := prettyjson.Format(data) if err != nil { log.Printf("prettyjson.Marshal failed. Err: %v\n", err) diff --git a/examples/streaming/microphone/main.go b/examples/streaming/microphone/main.go index a481c00b..6f7da2f5 100644 --- a/examples/streaming/microphone/main.go +++ b/examples/streaming/microphone/main.go @@ -57,10 +57,10 @@ func main() { LogLevel: client.LogLevelDefault, // LogLevelDefault, LogLevelFull, LogLevelTrace }) - // context + // Go context ctx := context.Background() - // options + // set the Transcription options options := interfaces.LiveTranscriptionOptions{ Language: "en-US", Punctuate: true, @@ -69,16 +69,17 @@ func main() { SampleRate: 16000, } - // callback + // implement your own callback callback := MyCallback{} + // create a Deepgram client dgClient, err := client.NewWithDefaults(ctx, options, callback) if err != nil { log.Println("ERROR creating LiveTranscription connection:", err) return } - // call connect! + // connect the websocket to Deepgram wsconn := dgClient.Connect() if wsconn == nil { log.Println("Client.Connect failed") diff --git a/examples/streaming/replay/main.go b/examples/streaming/replay/main.go index b7229d28..9e3a0a78 100644 --- a/examples/streaming/replay/main.go +++ b/examples/streaming/replay/main.go @@ -24,10 +24,10 @@ func main() { // init library client.InitWithDefault() - // context + // Go context ctx := context.Background() - // options + // set the Transcription options options := interfaces.LiveTranscriptionOptions{ Language: "en-US", Punctuate: true, @@ -36,13 +36,14 @@ func main() { SampleRate: 8000, } + // create a Deepgram client dgClient, err := client.NewForDemo(ctx, options) if err != nil { log.Println("ERROR creating LiveTranscription connection:", err) return } - // call connect! + // connect the websocket to Deepgram wsconn := dgClient.Connect() if wsconn == nil { log.Println("Client.Connect failed")