Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
glsx-serivce
/
audio-text
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 8b20b763
authored
May 29, 2024
by
胡悦
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
修复,并修改端口号可以输入
1 parent
bdf0487d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
54 deletions
app.js
fileTrans.js
package.json
app.js
View file @
8b20b76
...
@@ -3,24 +3,51 @@
...
@@ -3,24 +3,51 @@
* @Author: huyue
* @Author: huyue
* @Date: 2024-05-23 17:35:22
* @Date: 2024-05-23 17:35:22
* @LastEditors: huyue
* @LastEditors: huyue
* @LastEditTime: 2024-05-2
8 17:09:19
* @LastEditTime: 2024-05-2
9 16:31:04
*/
*/
'use strict'
;
'use strict'
;
const
ALIYUN_AK_ID
=
'LTAI5t8m8DpaffMDhR8YWqWz'
const
ALIYUN_AK_SECRET
=
'pHE4l5pUFuKJcF3t6v09Pxdm3mitpd'
const
NLS_APP_KEY
=
'wtWTUAwcMbuf60NY'
const
express
=
require
(
"express"
);
const
express
=
require
(
"express"
);
const
app
=
express
();
const
app
=
express
();
const
port
=
3000
;
const
path
=
require
(
"path"
);
const
port
=
process
.
argv
[
4
]
||
3000
;
const
fileTrans
=
require
(
'./fileTrans'
);
const
fileTrans
=
require
(
'./fileTrans'
);
require
(
'dotenv'
).
config
();
require
(
'dotenv'
).
config
();
app
.
use
(
require
(
'body-parser'
).
urlencoded
({
extended
:
false
}))
app
.
use
(
require
(
'body-parser'
).
urlencoded
({
extended
:
false
}))
// 用于解析 multipart/form-data 类型的表单数据
// 用于解析 multipart/form-data 类型的表单数据
const
multer
=
require
(
'multer'
);
const
multer
=
require
(
'multer'
);
const
upload
=
multer
({
dest
:
'uploads/'
});
// 设置上传文件的存储路径
app
.
use
(
express
.
json
())
app
.
use
(
express
.
urlencoded
({
extended
:
true
}));
// 表示form-data中普通数据的处理,不能用于文件的处理
// app.use(upload.any())
console
.
log
(
process
.
argv
,
process
.
argv
[
4
])
app
.
use
(
express
.
static
(
'public'
));
// 提供静态文件服务
app
.
use
(
express
.
static
(
'public'
));
// 提供静态文件服务
// 为上传的文件添加后缀和文件名
const
storage
=
multer
.
diskStorage
({
destination
:
function
(
req
,
file
,
cb
)
{
cb
(
null
,
'uploads/'
)
},
filename
:
function
(
req
,
file
,
cb
)
{
cb
(
null
,
Date
.
now
()
+
path
.
extname
(
file
.
originalname
))
}
})
const
upload
=
multer
({
// dest: 'uploads/'
storage
});
// 设置上传文件的存储路径
// 上传文件
// 上传文件
app
.
post
(
'/upload'
,
upload
.
single
(
'file'
),
(
req
,
res
)
=>
{
app
.
post
(
'/upload'
,
upload
.
single
(
'file'
),
(
req
,
res
)
=>
{
console
.
log
(
req
.
file
)
if
(
req
.
file
)
{
if
(
req
.
file
)
{
res
.
send
(
req
.
file
.
path
);
// const domain = 'http://192.168.1.68:9797/uploads/'
const
domain
=
'http://audio-text.dev.glsx.com.cn/uploads/'
res
.
send
(
domain
+
req
.
file
.
originalname
);
}
else
{
}
else
{
res
.
status
(
400
).
send
(
'未选择文件'
);
res
.
status
(
400
).
send
(
'未选择文件'
);
}
}
...
@@ -34,9 +61,9 @@ app.post('/fileTrans', (req, res) => {
...
@@ -34,9 +61,9 @@ app.post('/fileTrans', (req, res) => {
fileLink
=
'https://glsk-oss.oss-cn-shenzhen.aliyuncs.com/quality/1716455618363.mp3'
fileLink
=
'https://glsk-oss.oss-cn-shenzhen.aliyuncs.com/quality/1716455618363.mp3'
}
}
// 假设这是调用fileTrans方法的逻辑
// 假设这是调用fileTrans方法的逻辑
const
akId
=
process
.
env
.
ALIYUN_AK_ID
;
const
akId
=
ALIYUN_AK_ID
;
const
akSecret
=
process
.
env
.
ALIYUN_AK_SECRET
;
const
akSecret
=
ALIYUN_AK_SECRET
;
const
appKey
=
process
.
env
.
NLS_APP_KEY
;
const
appKey
=
NLS_APP_KEY
;
fileTrans
(
akId
,
akSecret
,
appKey
,
fileLink
,
(
err
,
result
)
=>
{
fileTrans
(
akId
,
akSecret
,
appKey
,
fileLink
,
(
err
,
result
)
=>
{
if
(
err
)
{
if
(
err
)
{
...
@@ -46,4 +73,6 @@ app.post('/fileTrans', (req, res) => {
...
@@ -46,4 +73,6 @@ app.post('/fileTrans', (req, res) => {
}
}
});
});
});
});
app
.
listen
(
port
);
\ No newline at end of file
\ No newline at end of file
app
.
listen
(
port
,
()
=>
{
console
.
log
(
`服务器运行在 http://localhost:
${
port
}
`
);
});
\ No newline at end of file
\ No newline at end of file
fileTrans.js
View file @
8b20b76
...
@@ -97,49 +97,4 @@ function fileTrans(akID, akSecret, appKey, fileLink, callback) {
...
@@ -97,49 +97,4 @@ function fileTrans(akID, akSecret, appKey, fileLink, callback) {
console
.
error
(
error
);
console
.
error
(
error
);
});
});
}
}
var
akId
=
process
.
env
.
ALIYUN_AK_ID
;
var
akSecret
=
process
.
env
.
ALIYUN_AK_SECRET
;
var
appKey
=
process
.
env
.
NLS_APP_KEY
;
// var fileLink = 'https://gw.alipayobjects.com/os/bmw-prod/0574ee2e-f494-45a5-820f-63aee583045a.wav';
// var fileLink = 'https://glsk-oss.oss-cn-shenzhen.aliyuncs.com/quality/merged_17147921591051714790340660.mp3'; // 30min 888B
// var fileLink = 'https://glsk-oss.oss-cn-shenzhen.aliyuncs.com/quality/merged_17145565338941714555767316.mp3'; // 13min 887B
// var fileLink = 'https://glsk-oss.oss-cn-shenzhen.aliyuncs.com/quality/merged_17161064828751716105678129.mp3'; // 13:23 885B
// var fileLink = 'https://glsk-oss.oss-cn-shenzhen.aliyuncs.com/quality/1716443889303.mp3';
// var fileLink = 'https://glsk-oss.oss-cn-shenzhen.aliyuncs.com/quality/merged_17161083134331716107368353.mp3';
var
fileLink
=
'https://glsk-oss.oss-cn-shenzhen.aliyuncs.com/quality/1716455618363.mp3'
;
// var fileLink = 'https://glsk-oss.oss-cn-shenzhen.aliyuncs.com/quality/output.wav';
// 转换音频文件
// function convertAudio(inputPath, outputPath, sampleRate, callback) {
// ffmpeg(inputPath)
// .audioFrequency(sampleRate) // 设置目标采样率
// .output(outputPath)
// .on('error', (err) => {
// console.error('Error:', err);
// callback(err, null);
// })
// .on('end', () => {
// // 转换完成后读取文件内容
// fs.readFile(outputPath, (err, data) => {
// if (err) {
// console.error('Error reading file:', err);
// callback(err, null);
// } else {
// // 将文件内容传递给回调函数
// callback(null, data);
// }
// });
// });
// }
// // 调用转换函数
// convertAudio(fileLink, 'output.wav', 16000, (err, fileAudio) => {
// if (err) {
// console.error('Conversion failed:', err);
// } else {
// // 执行其他函数,例如 fileTrans
// fileTrans(akId, akSecret, appKey, fileAudio);
// // fileTrans(fileAudio);
// }
// });
// fileTrans(akId, akSecret, appKey, fileLink);
module
.
exports
=
fileTrans
;
module
.
exports
=
fileTrans
;
\ No newline at end of file
\ No newline at end of file
package.json
View file @
8b20b76
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
"main"
:
"index.js"
,
"main"
:
"index.js"
,
"scripts"
:
{
"scripts"
:
{
"test"
:
"echo
\"
Error: no test specified
\"
&& exit 1"
,
"test"
:
"echo
\"
Error: no test specified
\"
&& exit 1"
,
"start"
:
"node app.js"
"start"
:
"node app.js
--port $npm_package_config_port
"
},
},
"keywords"
:
[],
"keywords"
:
[],
"author"
:
""
,
"author"
:
""
,
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment