Skip to content

Commit

Permalink
added example for convertToMP3.
Browse files Browse the repository at this point in the history
  • Loading branch information
kingmariano committed Jul 20, 2024
1 parent 0fc2233 commit fce2c62
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions _examples/convertToMP3/convertToMP3.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package main

import (
"context"
"encoding/json"
"fmt"
"os"

"github.com/kingmariano/omnicron-go"
)

func main() {
apiKey := "YOUR_API_KEY"
audioFile, err := os.Open("sample1.wav")
if err != nil {
fmt.Printf("Error converting file to mp3: %v\n", err)
return
}
client := omnicron.NewClient(apiKey, omnicron.WithBaseURL("https://omnicron-latest.onrender.com/"))
res, err := client.ConvertToMP3(context.Background(), omnicron.ConvertToMP3Params{
File: audioFile,
})
if err != nil {
fmt.Printf("Error downloading video url : %v\n", err)
return
}

// Marshal the response to JSON
jsonData, err := json.MarshalIndent(res, "", " ")
if err != nil {
fmt.Printf("Error marshaling JSON: %v\n", err)
return
}

// Write JSON data to a file
file, err := os.Create("file.json")
if err != nil {
fmt.Printf("Error creating file: %v\n", err)
return
}
defer file.Close()

_, err = file.Write(jsonData)
if err != nil {
fmt.Printf("Error writing JSON to file: %v\n", err)
return
}

fmt.Println("JSON data written to file.json successfully")
}

0 comments on commit fce2c62

Please sign in to comment.