-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0fc2233
commit fce2c62
Showing
1 changed file
with
50 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
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") | ||
} |