-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add whisper to the examples directory (#4)
* Add whisper to the examples directory * Add whisper to the readme
- Loading branch information
Marwan Sulaiman
authored
Mar 3, 2023
1 parent
e332e66
commit 46c1e82
Showing
2 changed files
with
34 additions
and
0 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,33 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"os" | ||
|
||
"github.com/rakyll/openai-go" | ||
"github.com/rakyll/openai-go/whisper" | ||
) | ||
|
||
func main() { | ||
sesh := openai.NewSession(os.Getenv("OPENAI_API_KEY")) | ||
wc := whisper.NewClient(sesh, "") | ||
filePath := os.Getenv("AUDIO_FILE_PATH") | ||
if filePath == "" { | ||
log.Fatal("must provide an AUDIO_FILE_PATH env var") | ||
} | ||
f, err := os.Open(filePath) | ||
if err != nil { | ||
log.Fatalf("error opening audio file: %v", err) | ||
} | ||
defer f.Close() | ||
resp, err := wc.Transcribe(context.TODO(), &whisper.CreateCompletionParams{ | ||
Language: "en", | ||
Audio: f, | ||
AudioFormat: "mp3", | ||
}) | ||
if err != nil { | ||
log.Fatalf("error transcribing file: %v", err) | ||
} | ||
log.Println(resp.Text) | ||
} |