Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Example Comments #140

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions examples/manage/invitations/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/manage/members/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions examples/manage/scopes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
28 changes: 15 additions & 13 deletions examples/prerecorded/file/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -56,20 +55,23 @@ 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)
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)
Expand Down
23 changes: 12 additions & 11 deletions examples/prerecorded/stream/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,28 @@ 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)
os.Exit(1)
}
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)
Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions examples/prerecorded/url/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func main() {
// context
ctx := context.Background()

// options
// send stream to Deepgram
options := interfaces.PreRecordedTranscriptionOptions{
Punctuate: true,
Diarize: true,
Expand All @@ -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)
Expand All @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions examples/streaming/microphone/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand Down
7 changes: 4 additions & 3 deletions examples/streaming/replay/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand Down