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

adds examples for testing #81

Merged
merged 4 commits into from
Aug 28, 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
107 changes: 60 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
# Deepgram Go SDK

Community Go SDK for [Deepgram](https://www.deepgram.com/). Power your apps with world-class speech and Language AI models.
Community Go SDK for [Deepgram](https://www.deepgram.com/). Start building with our powerful transcription & speech understanding API.

> This SDK only supports hosted usage of api.deepgram.com.

* [Deepgram Go SDK](#deepgram-go-sdk)
* [Getting an API Key](#getting-an-api-key)
* [Documentation](#documentation)
* [Installation](#installation)
* [Requirements](#requirements)
* [Configuration](#configuration)
* [Transcription](#transcription)
* [Remote Files](#remote-files)
* [UrlSource](#urlsource)
* [Local files](#local-files)
* [ReadStreamSource](#readstreamsource)
* [PrerecordedTranscriptionOptions](#prerecordedtranscriptionoptions)
* [Generating Captions](#generating-captions)
* [Live Audio](#live-audio)
* [LiveTranscriptionOptions](#livetranscriptionoptions)
* [Projects](#projects)
* [Get Projects](#get-projects)
* [Get Project](#get-project)
* [Update Project](#update-project)
* [Delete Project](#delete-project)
* [Keys](#keys)
* [List Keys](#list-keys)
* [Get Key](#get-key)
* [Create Key](#create-key)
* [Delete Key](#delete-key)
* [Members](#members)
* [Get Members](#get-members)
* [Remove Member](#remove-member)
* [Scopes](#scopes)
* [Get Member Scopes](#get-member-scopes)
* [Update Scope](#update-scope)
* [Invitations](#invitations)
* [List Invites](#list-invites)
* [Send Invite](#send-invite)
* [Delete Invite](#delete-invite)
* [Leave Project](#leave-project)
* [Usage](#usage)
* [Get All Requests](#get-all-requests)
* [UsageRequestListOptions](#usagerequestlistoptions)
* [Get Request](#get-request)
* [Summarize Usage](#summarize-usage)
* [UsageOptions](#usageoptions)
* [Get Fields](#get-fields)
* [GetUsageFieldsOptions](#getusagefieldsoptions)
* [Development and Contributing](#development-and-contributing)
* [Getting Help](#getting-help)
- [Deepgram Go SDK](#deepgram-go-sdk)
- [Getting an API Key](#getting-an-api-key)
- [Documentation](#documentation)
- [Installation](#installation)
- [Requirements](#requirements)
- [Configuration](#configuration)
- [Transcription](#transcription)
- [Remote Files](#remote-files)
- [UrlSource](#urlsource)
- [Local files](#local-files)
- [ReadStreamSource](#readstreamsource)
- [PrerecordedTranscriptionOptions](#prerecordedtranscriptionoptions)
- [Generating Captions](#generating-captions)
- [Live Audio](#live-audio)
- [LiveTranscriptionOptions](#livetranscriptionoptions)
- [Projects](#projects)
- [Get Projects](#get-projects)
- [Get Project](#get-project)
- [Update Project](#update-project)
- [Delete Project](#delete-project)
- [Keys](#keys)
- [List Keys](#list-keys)
- [Get Key](#get-key)
- [Create Key](#create-key)
- [Delete Key](#delete-key)
- [Members](#members)
- [Get Members](#get-members)
- [Remove Member](#remove-member)
- [Scopes](#scopes)
- [Get Member Scopes](#get-member-scopes)
- [Update Scope](#update-scope)
- [Invitations](#invitations)
- [List Invites](#list-invites)
- [Send Invite](#send-invite)
- [Delete Invite](#delete-invite)
- [Leave Project](#leave-project)
- [Usage](#usage)
- [Get All Requests](#get-all-requests)
- [UsageRequestListOptions](#usagerequestlistoptions)
- [Get Request](#get-request)
- [Summarize Usage](#summarize-usage)
- [UsageOptions](#usageoptions)
- [Get Fields](#get-fields)
- [GetUsageFieldsOptions](#getusagefieldsoptions)
- [Development and Contributing](#development-and-contributing)
- [Getting Help](#getting-help)

# Getting an API Key

Expand All @@ -75,6 +75,19 @@ go get github.com/deepgram-devs/deepgram-go-sdk
dg := deepgram.NewClient(DEEPGRAM_API_KEY)
```

# Testing

## Using Example Projects to test new features

Contributors to the SDK can test their changes locally by running the projects in the `examples` folder. This can be done when making changes without adding a unit test, but of course it is recommended that you add unit tests for any feature additions made to the SDK.

Go to the folder `examples` and look for these two projects, which can be used to test out features in the Deepgram Go SDK:

- prerecorded
- streaming

These are standalone projects, so you will need to follow the instructions in the README.md files for each project to get it running.

# Transcription

## Remote Files
Expand Down
35 changes: 35 additions & 0 deletions examples/README.md
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
```
65 changes: 0 additions & 65 deletions examples/liveTranscription_example.go

This file was deleted.

56 changes: 0 additions & 56 deletions examples/preRecordedFromStream_example.go

This file was deleted.

43 changes: 0 additions & 43 deletions examples/preRecordedFromUrl_example.go

This file was deleted.

71 changes: 71 additions & 0 deletions examples/prerecorded/main.go
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://")
}
Loading