声卡音频上传接口修改

This commit is contained in:
1 2025-06-23 11:01:42 +08:00
parent 70b0895bf6
commit 7d23747811
2 changed files with 58 additions and 14 deletions

BIN
dist.zip

Binary file not shown.

View File

@ -1238,19 +1238,62 @@ export default {
const formData = new FormData();
formData.append('file', audioBlob, `recording_${Date.now()}.mp3`);
// TODO: API
// const response = await uploadFile(formData);
// 使 HTTP HTTP
const uploadUrl = 'https://iot-xcwl.cn/common/upload/audio';
// const uploadUrl = 'http://1.94.62.14:8080/common/upload/audio';
//
const response = await fetch(uploadUrl, {
method: 'POST',
headers: {
'Authorization': 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6ImU3MWM2OTg4LTNlMzMtNDYyMy05M2M3LWE4YzZmMTNlMjZkZSJ9.wgsL8b3WDmyuesG8JTA3LcNFp2FigkB90h6Inwxt7OFadH6rc5np5TjAyU1pzU2_b5cmG8BYXMEdAqEdJzoDcA'
},
body: formData
});
if (response.ok) {
const result = await response.json();
if (result.code === 200) {
this.$message.success('上传成功');
this.recordings.unshift({
name: `录音_${this.formatTime(this.recordingTime)}`,
time: new Date().toLocaleString()
});
// URL MQTT 103#onlinePlay
if (result.url) {
const onlinePlayModel = this.deviceInfo.thingsModels.find(model => model.id === '103#onlinePlay');
if (onlinePlayModel) {
// interrupt JSON
const playData = {
"online_play": {
url: "http://1.94.62.14:8080" + result.resourcePath,
},
interrupt: 98
};
onlinePlayModel.shadow = JSON.stringify(playData);
await this.mqttPublish(this.deviceInfo, onlinePlayModel);
this.$message.success('音频已下发到设备');
} else {
this.$message.warning('未找到 103#onlinePlay 物模型');
}
}
//
this.reRecord();
} else {
this.$message.error(result.msg || '上传失败');
}
} else {
this.$message.error('上传失败,请检查网络连接');
}
} catch (error) {
//
if (error.message && error.message.includes('Mixed Content')) {
this.$message.error('由于安全策略,无法在 HTTPS 页面访问 HTTP 接口。请联系管理员配置接口支持 HTTPS。');
} else {
this.$message.error('上传失败');
}
console.error('上传错误:', error);
}
},
@ -1330,7 +1373,8 @@ export default {
vol: this.newAudio.vol,
tex_utf8: this.newAudio.tex_utf8,
filename: filename,
}
},
"interrupt": 99
};