-
-
Save simonw/75e9fbec4cf7356bd324307bed09ad01 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/bin/bash | |
| # Check if jq is installed | |
| if ! command -v jq &> /dev/null; then | |
| echo "Error: jq is not installed. Please install it to run this script." | |
| exit 1 | |
| fi | |
| # Check if both arguments are provided | |
| if [ $# -ne 2 ]; then | |
| echo "Usage: $0 <text_prompt> <audio_file_path>" | |
| exit 1 | |
| fi | |
| TEXT_PROMPT="$1" | |
| AUDIO_FILE="$2" | |
| # Check if the audio file exists | |
| if [ ! -f "$AUDIO_FILE" ]; then | |
| echo "Error: Audio file does not exist: $AUDIO_FILE" | |
| exit 1 | |
| fi | |
| # Base64 encode the audio file | |
| AUDIO_BASE64=$(base64 < "$AUDIO_FILE" | tr -d '\n') | |
| # Construct the JSON payload | |
| JSON_PAYLOAD=$(jq -n \ | |
| --arg model "gpt-4o-audio-preview" \ | |
| --arg text "$TEXT_PROMPT" \ | |
| --arg audio "$AUDIO_BASE64" \ | |
| '{ | |
| model: $model, | |
| modalities: ["text"], | |
| messages: [ | |
| { | |
| role: "user", | |
| content: [ | |
| {type: "text", text: $text}, | |
| { | |
| type: "input_audio", | |
| input_audio: { | |
| data: $audio, | |
| format: "wav" | |
| } | |
| } | |
| ] | |
| } | |
| ] | |
| }') | |
| # Make the API call | |
| curl -s "https://api.openai.com/v1/chat/completions" \ | |
| -H "Content-Type: application/json" \ | |
| -H "Authorization: Bearer $OPENAI_API_KEY" \ | |
| -d "$JSON_PAYLOAD" | jq . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment