-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from dvonthenen/example-live-with-microphone
Implement Microphone Streaming Example and Clean Up Other Examples
- Loading branch information
Showing
23 changed files
with
555 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Binaries for programs and plugins | ||
.DS_Store | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.o | ||
*.a | ||
*.so | ||
*.dylib | ||
|
||
# Folders | ||
_obj | ||
_test | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
# cgo stuff | ||
*.cgo1.go | ||
*.cgo2.c | ||
_cgo_defun.c | ||
_cgo_gotypes.go | ||
_cgo_export.* | ||
_testmain.go | ||
.idea/ | ||
*.iml |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// 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-devs/deepgram-go-sdk/pkg/api/prerecorded/v1" | ||
interfaces "github.com/deepgram-devs/deepgram-go-sdk/pkg/client/interfaces" | ||
client "github.com/deepgram-devs/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.LogLevelFull, | ||
}) | ||
|
||
// context | ||
ctx := context.Background() | ||
|
||
//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, | ||
}, | ||
) | ||
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) | ||
} | ||
|
||
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) | ||
} |
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// 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-devs/deepgram-go-sdk/pkg/api/prerecorded/v1" | ||
interfaces "github.com/deepgram-devs/deepgram-go-sdk/pkg/client/interfaces" | ||
client "github.com/deepgram-devs/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.LogLevelFull, | ||
}) | ||
|
||
// context | ||
ctx := context.Background() | ||
|
||
//client | ||
c := client.NewWithDefaults() | ||
dg := prerecorded.New(c) | ||
|
||
// send file stream | ||
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, | ||
}, | ||
) | ||
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) | ||
} | ||
|
||
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// 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-devs/deepgram-go-sdk/pkg/api/prerecorded/v1" | ||
interfaces "github.com/deepgram-devs/deepgram-go-sdk/pkg/client/interfaces" | ||
client "github.com/deepgram-devs/deepgram-go-sdk/pkg/client/prerecorded" | ||
) | ||
|
||
const ( | ||
url string = "https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav" | ||
) | ||
|
||
func main() { | ||
// init library | ||
client.InitWithDefault() | ||
|
||
// context | ||
ctx := context.Background() | ||
|
||
//client | ||
c := client.NewWithDefaults() | ||
dg := prerecorded.New(c) | ||
|
||
// send stream | ||
res, err := dg.FromURL( | ||
ctx, | ||
url, | ||
interfaces.PreRecordedTranscriptionOptions{ | ||
Punctuate: true, | ||
Diarize: true, | ||
Language: "en-US", | ||
Utterances: true, | ||
Redact: []string{"pci", "ssn"}, | ||
}, | ||
) | ||
if err != nil { | ||
log.Printf("FromURL 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) | ||
} | ||
|
||
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Live API (Real-Time) Example | ||
|
||
This example uses the Microphone as input in order to detect conversation insights in what is being said. This example required additional components (for the microphone) to be installed in order for this example to function correctly. | ||
|
||
## Configuration | ||
|
||
The SDK (and this example) needs to be initialized with your account's credentials `DEEPGRAM_API_KEY`, which are available in your [Deepgram Console][dg-console]. If you don't have a Deepgram account, you can [sign up here][dg-signup] for free. | ||
|
||
You must add your `DEEPGRAM_API_KEY` to your list of environment variables. We use environment variables because they are easy to configure, support PaaS-style deployments, and work well in containerized environments like Docker and Kubernetes. | ||
|
||
```sh | ||
export DEEPGRAM_API_KEY=YOUR-APP-KEY-HERE | ||
``` | ||
|
||
## Installation | ||
|
||
The Live API (Real-Time) example makes use of a [microphone package](https://github.com/deepgram-devs/deepgram-go-sdk/tree/main/pkg/audio/microphone) contained within the repository. That package makes use of the [PortAudio library](http://www.portaudio.com/) which is a cross-platform open source audio library. If you are on Linux, you can install this library using whatever package manager is available (yum, apt, etc.) on your operating system. If you are on macOS, you can install this library using [brew](https://brew.sh/). | ||
|
||
[dg-console]: https://console.deepgram.com/ | ||
[dg-signup]: https://console.deepgram.com/signup |
Oops, something went wrong.