提交 fca501dd 编写于 作者: P practicer2015

Tue Mar 18 16:50:00 CST 2025 inscode

上级 669eac6d
console.log("欢迎来到 InsCode"); const express = require('express');
\ No newline at end of file const multer = require('multer');
const tencentcloud = require('tencentcloud-sdk-nodejs');
const app = express();
const upload = multer({ dest: 'uploads/' });
// 腾讯云语音识别客户端
const AsrClient = tencentcloud.asr.v20190614.Client;
const client = new AsrClient({
credential: {
secretId: 'your-secret-id', // 替换为你的 SecretId
secretKey: 'your-secret-key' // 替换为你的 SecretKey
},
region: 'ap-guangzhou',
profile: {
httpProfile: {
endpoint: 'asr.tencentcloudapi.com'
}
}
});
// 处理上传的录音文件
app.post('/speech-to-text', upload.single('audio'), (req, res) => {
const filePath = req.file.path;
// 调用腾讯云语音识别 API
const params = {
EngineModelType: '16k_zh', // 16k 中文普通话
Url: filePath // 本地文件路径需要先上传到云存储
};
client.CreateRecTask(params).then(
(data) => {
res.json({ code: 0, text: data.Result });
},
(err) => {
res.json({ code: 1, message: err.message });
}
);
});
app.listen(3000, () => {
console.log('Server is running on http://localhost:3000');
});
\ No newline at end of file
...@@ -4,15 +4,18 @@ ...@@ -4,15 +4,18 @@
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"dev": "node index.js", "dev": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"keywords": [], "keywords": [],
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@types/node": "^18.0.6", "@types/node": "^18.0.6",
"node-fetch": "^3.2.6" "expres": "^0.0.5",
"express": "^4.21.2",
"multer": "^1.4.5-lts.1",
"node-fetch": "^3.2.6",
"tencentcloud-sdk-nodejs": "^4.0.1053"
} }
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册