Files
go-openai/examples/voice-to-text/main.go
Hoani Bryson 5f4ff3ebfa Add Readme example to example_test.go (#298)
* Add speech to text example in docs

* Add caption formats for audio transcription

* Add caption example to README

* Address sanity check errors

* Add tests for decodeResponse

* Use typechecker for audio response format

* Decoding response refactors

* Migrated examples to example_test.go

* Add some executable examples

* Update error docs

* Avoid linting example files which break conventions

* Restore README examples

* Enable linting for example_test
2023-05-08 20:16:01 +04:00

36 lines
654 B
Go

package main
import (
"context"
"errors"
"fmt"
"os"
"github.com/sashabaranov/go-openai"
)
func main() {
if len(os.Args) < 2 {
fmt.Println("please provide a filename to convert to text")
return
}
if _, err := os.Stat(os.Args[1]); errors.Is(err, os.ErrNotExist) {
fmt.Printf("file %s does not exist\n", os.Args[1])
return
}
client := openai.NewClient(os.Getenv("OPENAI_API_KEY"))
resp, err := client.CreateTranscription(
context.Background(),
openai.AudioRequest{
Model: openai.Whisper1,
FilePath: os.Args[1],
},
)
if err != nil {
fmt.Printf("Transcription error: %v\n", err)
return
}
fmt.Println(resp.Text)
}