Skip to content

Commit

Permalink
fix: 处理opanai语音识别报错的问题
Browse files Browse the repository at this point in the history
--bug=1046791 --user=刘瑞斌 【应用】使用 openai 语音输入模型、输出模型进行输入输出报错 https://www.tapd.cn/57709429/s/1582133
  • Loading branch information
liuruibin committed Sep 20, 2024
1 parent 6d39cd8 commit a2aab8d
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import asyncio
import io
from typing import Dict

from openai import OpenAI
Expand Down Expand Up @@ -49,5 +51,9 @@ def speech_to_text(self, audio_file):
base_url=self.api_base,
api_key=self.api_key
)
res = client.audio.transcriptions.create(model=self.model, language="zh", file=audio_file)
audio_data = audio_file.read()
buffer = io.BytesIO(audio_data)
buffer.name = "file.mp3" # this is the important line
res = client.audio.transcriptions.create(model=self.model, language="zh", file=buffer)
return res.text

0 comments on commit a2aab8d

Please sign in to comment.