Skip to content

Commit 33f2620

Browse files
committed
fix: fix bailian stt
1 parent 1113e1f commit 33f2620

File tree

1 file changed

+8
-1
lines changed
  • apps/setting/models_provider/impl/aliyun_bai_lian_model_provider/model

1 file changed

+8
-1
lines changed

apps/setting/models_provider/impl/aliyun_bai_lian_model_provider/model/stt.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import dashscope
66
from dashscope.audio.asr import (Recognition)
7+
from pydub import AudioSegment
78

89
from setting.models_provider.base_model_provider import MaxKBBaseModel
910
from setting.models_provider.impl.base_stt import BaseSpeechToText
@@ -40,7 +41,6 @@ def speech_to_text(self, audio_file):
4041
dashscope.api_key = self.api_key
4142
recognition = Recognition(model=self.model,
4243
format='mp3',
43-
sample_rate=16000,
4444
callback=None)
4545
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
4646
# 将上传的文件保存到临时文件中
@@ -49,6 +49,13 @@ def speech_to_text(self, audio_file):
4949
temp_file_path = temp_file.name
5050

5151
try:
52+
audio = AudioSegment.from_file(temp_file_path)
53+
if audio.channels != 1:
54+
audio = audio.set_channels(1)
55+
audio = audio.set_frame_rate(16000)
56+
57+
# 将转换后的音频文件保存到临时文件中
58+
audio.export(temp_file_path, format='mp3')
5259
# 识别临时文件
5360
result = recognition.call(temp_file_path)
5461
text = ''

0 commit comments

Comments
 (0)