Android - 意外响应代码 400 - 使用 Volley 将 MP3 发布到 OpenAI Whisper

问题描述 投票:0回答:0

女士们先生们,您好,

i 和 Volley 有一个小项目。 目前我尝试发布我录制的 MP3 并将我存储在 cacheDir.

private var audioFile: File? = null

File(cacheDir, "audio.mp3")

感谢大家的关注,祝你们一切顺利

耳语医生。 https://platform.openai.com/docs/api-reference/audio/create

错误: NetworkUtility.shouldRetryException:意外的响应代码 400 https://api.openai.com/v1/audio/transcriptions 错误是:空 com.android.volley.ClientError

private fun getResponseWhisper(query: File?) {
//      setting text on for question on below line.
your_input.text = getString(R.string.placeholder)
//       creating a queue for request queue.
val queue: RequestQueue = Volley.newRequestQueue(applicationContext)
//       creating a json object on below line.


val jsonObject: JSONObject? = JSONObject()
//       adding params to json object.
jsonObject?.put("file", "${query}")
jsonObject?.put("model", "whisper-1")


Log.e("API LINK", "$jsonObject")

//       on below line making json object request.
val postRequest: JsonObjectRequest =
    //      on below line making json object request.
    object : JsonObjectRequest(Method.POST, OPEN_AI_WHISPER, jsonObject,
        Response.Listener { response ->
            //       on below line getting response message and setting it to text view.

            val responseMsg: JSONObject = response.getJSONObject("text")
            your_input.text = responseMsg.toString()
            start_Button.text = getString(R.string.speech_recognition_Send_Button_String)
            start_Button.isClickable = true
            identifyLanguageWithStringInput(responseMsg.toString())


        },
        //       adding on error listener
        Response.ErrorListener { error ->
            Log.e("TAGAPI", "Error is : " + error.message + "\n" + error)

        }) {
        override fun getHeaders(): MutableMap<String, String> {
            val params: MutableMap<String, String> = HashMap()
            //       adding headers on below line.
            params["Authorization"] = "Bearer $OPEN_AI_API_KEY"
            params["Content-Type"] = "multipart/form-data"
            return params;
        }

    }
android kotlin post android-volley
© www.soinside.com 2019 - 2024. All rights reserved.