Die Anfrage lautet:
Code: Select all
curl https://api.openai.com/v1/audio/transcriptions \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: multipart/form-data" \
-F file="@/path/to/file/audio.mp3" \
-F model="gpt-4o-mini-transcribe" \
-F stream=true
Delta:
Code: Select all
data: {"type":"transcript.text.delta","delta":"I","logprobs":[{"token":"I","logprob":-0.00007588794,"bytes":[73]}]}
Code: Select all
data: {"type":"transcript.text.done","text":"I see skies of blue and clouds of white, the bright blessed days, the dark sacred nights, and I think to myself, what a wonderful world.","logprobs":[{"token":"I","logprob":-0.00007588794,"bytes":[73]},.....}
Code: Select all
private fun getAnswer(retrofitAPI: ApiService, modal: ChatGPTRequest, gson: Gson) = flow {
val response = retrofitAPI.getStreams(modal).execute()
if (response.isSuccessful) {
if (response.isSuccessful) {
val input = response.body()?.byteStream()?.bufferedReader() ?: throw Exception()
try {
while (currentCoroutineContext().isActive) {
val line = input.readLine()
if (line != null && line.startsWith("data:")) {
try {
val answerDetailInfo = gson.fromJson(
line.substring(5).trim(),
ChatGPTResponse::class.java
)
emit(answerDetailInfo)
} catch (e: Exception) {
e.printStackTrace()
}
}
delay(100)
}
} catch (e: IOException) {
throw Exception(e)
} finally {
input.close()
}
} else {
throw HttpException(response)
}
}
}
Mobile version