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:
43
README.md
43
README.md
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user