d4bf3627fd
新增运动节拍RepClock全套小程序页面、后端API与数据库服务,新增subhub子工具汇总页面,优化全局主页样式与配置,为web静态资源添加版本缓存参数,补充配套调试脚本
39 lines
1.6 KiB
JavaScript
39 lines
1.6 KiB
JavaScript
const fs = require('fs')
|
|
const path = require('path')
|
|
const envPath = path.join(process.env.USERPROFILE || 'C:\\Users\\Administrator', 'Toolbox_local_creds.env.local')
|
|
if (fs.existsSync(envPath)) {
|
|
const text = fs.readFileSync(envPath, 'utf8')
|
|
for (const line of text.split(/\r?\n/)) {
|
|
if (!line || /^\s*#/.test(line)) continue
|
|
const i = line.indexOf('=')
|
|
if (i < 0) continue
|
|
const k = line.slice(0, i).trim(), v = line.slice(i + 1).trim().replace(/^["']|["']$/g, '')
|
|
if (k && !(k in process.env)) process.env[k] = v
|
|
}
|
|
}
|
|
global.__builtin_fetch = globalThis.fetch
|
|
const API_KEY = process.env.DASHSCOPE_API_KEY
|
|
;(async () => {
|
|
const url = 'https://dashscope.aliyuncs.com/api/v1/services/aigc/text2audio/text-to-audio'
|
|
const body = {
|
|
model: 'cosyvoice-v1',
|
|
input: { text: '热身开合跳' },
|
|
parameters: { voice: 'longruoxi_v1', format: 'mp3', sample_rate: 24000, volume: 1.0, speech_rate: 1.0 },
|
|
}
|
|
try {
|
|
const resp = await global.__builtin_fetch(url, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Authorization': `Bearer ${API_KEY}`,
|
|
'Content-Type': 'application/json',
|
|
'X-DashScope-Async': 'enable',
|
|
},
|
|
body: JSON.stringify(body),
|
|
})
|
|
console.log('status=', resp.status)
|
|
console.log('headers=', [...resp.headers.entries()].filter(([k]) => k.startsWith('x-dashscope') || k.startsWith('content') || k.startsWith('x-request') || k === 'date').map(([k, v]) => k + '=' + v).join(' '))
|
|
const txt = await resp.text()
|
|
console.log('body=\n' + txt)
|
|
} catch (e) { console.error('ERR', e && e.message ? e.message : e) }
|
|
})()
|