Adds support for audio captioning with Whisper (#267)

* 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
This commit is contained in:
Hoani Bryson
2023-04-21 01:07:04 +12:00
committed by GitHub
parent d6ab1b3a4f
commit ecdea45b67
5 changed files with 129 additions and 8 deletions

View File

@@ -223,6 +223,47 @@ func main() {
```
</details>
<details>
<summary>Audio Captions</summary>
```go
package main
import (
"context"
"fmt"
"os"
openai "github.com/sashabaranov/go-openai"
)
func main() {
c := openai.NewClient(os.Getenv("OPENAI_KEY"))
req := openai.AudioRequest{
Model: openai.Whisper1,
FilePath: os.Args[1],
Format: openai.AudioResponseFormatSRT,
}
resp, err := c.CreateTranscription(context.Background(), req)
if err != nil {
fmt.Printf("Transcription error: %v\n", err)
return
}
f, err := os.Create(os.Args[1] + ".srt")
if err != nil {
fmt.Printf("Could not open file: %v\n", err)
return
}
defer f.Close()
if _, err := f.WriteString(resp.Text); err != nil {
fmt.Printf("Error writing to file: %v\n", err)
return
}
}
```
</details>
<details>
<summary>DALL-E 2 image generation</summary>
@@ -420,4 +461,4 @@ func main() {
fmt.Println(resp.Choices[0].Message.Content)
}
```
</details>
</details>