-
Notifications
You must be signed in to change notification settings - Fork 34
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 #81 from deepgram-devs/sr-adds-examples-for-testing
adds examples for testing
- Loading branch information
Showing
7 changed files
with
250 additions
and
211 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
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,35 @@ | ||
# Examples for Testing Features Locally | ||
|
||
The example projects are meant to be used to test features locally by contributors working on this SDK. | ||
|
||
## Steps to Test Your Code | ||
|
||
If you are contributing changes to this SDK, you can test those changes by using the `prerecorded` or `streaming` projects in the `examples` folder. Here are the steps to follow: | ||
|
||
### Add Your Code | ||
|
||
Make your changes to the SDK (be sure you are on a branch you have created to do this work). | ||
|
||
### Install dependencies | ||
|
||
If the project requires third-party dependencies and not just standard library dependencies, you will have to install them. Make sure you are in the folder of the specific project (for example: `streaming`) and then use this command: | ||
|
||
``` | ||
go mod tidy | ||
``` | ||
|
||
### Edit the API key, the file, and the mimetype (as needed) | ||
|
||
Replace the API key where it says "YOUR_DEEPGRAM_API_KEY" | ||
|
||
```go | ||
DEEPGRAM_API_KEY = "YOUR_DEEPGRAM_API_KEY" | ||
``` | ||
|
||
### Run the project | ||
|
||
Make sure you're in the directory with the `main.go` file and run the project with the following command. | ||
|
||
``` | ||
go run main.go | ||
``` |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,71 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
"os" | ||
"strings" | ||
|
||
"github.com/deepgram-devs/deepgram-go-sdk/deepgram" | ||
) | ||
|
||
func main() { | ||
credentials := "DEEPGRAM_API_KEY" | ||
dg := deepgram.NewClient(credentials) | ||
|
||
filePath := "https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav" | ||
var res interface{} | ||
var err error | ||
|
||
if isURL(filePath) { | ||
res, err = dg.PreRecordedFromURL( | ||
deepgram.UrlSource{Url: filePath}, | ||
deepgram.PreRecordedTranscriptionOptions{ | ||
Punctuate: true, | ||
Diarize: true, | ||
Language: "en-US", | ||
Utterances: true, | ||
}, | ||
) | ||
if err != nil { | ||
fmt.Println("ERROR", err) | ||
return | ||
} | ||
} else { | ||
file, err := os.Open(filePath) | ||
if err != nil { | ||
log.Panicf("error opening file %s: %v", filePath, err) | ||
} | ||
defer file.Close() | ||
|
||
source := deepgram.ReadStreamSource{Stream: file, Mimetype: "YOUR_FILE_MIME_TYPE"} | ||
|
||
res, err = dg.PreRecordedFromStream( | ||
source, | ||
deepgram.PreRecordedTranscriptionOptions{ | ||
Punctuate: true, | ||
Diarize: true, | ||
Language: "en-US", | ||
Utterances: true, | ||
}, | ||
) | ||
if err != nil { | ||
fmt.Println("ERROR", err) | ||
return | ||
} | ||
} | ||
|
||
jsonStr, err := json.MarshalIndent(res, "", " ") | ||
if err != nil { | ||
fmt.Println("Error marshaling JSON:", err) | ||
return | ||
} | ||
|
||
log.Printf("%s", jsonStr) | ||
} | ||
|
||
// Function to check if a string is a valid URL | ||
func isURL(str string) bool { | ||
return strings.HasPrefix(str, "http://") || strings.HasPrefix(str, "https://") | ||
} |
Oops, something went wrong.