main
xushilin 3 months ago
parent fb857996ca
commit 477ec111c0

@ -2,11 +2,12 @@ let baseUrl = null;
if (process.env.NODE_ENV === 'production') { if (process.env.NODE_ENV === 'production') {
// 生产环境代码 // 生产环境代码
// baseUrl = 'http://huaerda-api.24yt.com'; // baseUrl = 'http://huaerda-api.24yt.com';
baseUrl = 'http://106.227.91.181:9081/api'; baseUrl = 'http://106.227.91.181:9020';
} else { } else {
// 非生产环境代码 // 非生产环境代码
// baseUrl = 'http://192.168.1.12:9020'; // baseUrl = 'http://192.168.1.12:9020';
baseUrl = 'http://106.227.91.181:9020' // baseUrl = 'http://106.227.91.181:9020'
baseUrl = 'http://106.227.91.181:9020';
} }
const config = { const config = {
baseUrl baseUrl

@ -85,6 +85,12 @@
"spotlight@3x" : "unpackage/res/icons/120x120.png" "spotlight@3x" : "unpackage/res/icons/120x120.png"
} }
} }
},
"splashscreen" : {
"androidStyle" : "common",
"android" : {
"hdpi" : "static/cxlogo.png"
}
} }
} }
}, },

@ -157,7 +157,6 @@
}, },
mounted() { mounted() {
this.screenWidth = uni.getSystemInfoSync().screenWidth; this.screenWidth = uni.getSystemInfoSync().screenWidth;
}, },
watch: { watch: {
isPlayingVoice(val) { isPlayingVoice(val) {
@ -167,7 +166,7 @@
this.current = -1; this.current = -1;
} }
this.current += 1; this.current += 1;
}, 500) }, 300)
}else{ }else{
if (this.voiceTimer) { if (this.voiceTimer) {
clearInterval(this.voiceTimer) clearInterval(this.voiceTimer)
@ -572,7 +571,7 @@
.ai-voice-play { .ai-voice-play {
width: 60px; width: 60px;
background-color: #fff; background-color: #F3F7F9;
margin-bottom: 10px; margin-bottom: 10px;
padding: 10px 12px; padding: 10px 12px;
border-radius: 14px; border-radius: 14px;

@ -29,9 +29,7 @@
getAIResponse, getAIResponse,
} from "@/api/index.js"; } from "@/api/index.js";
import { import {
textToSpeech, textToSpeech
base64ToFile,
removeFile
} from '@/utils/utils.js' } from '@/utils/utils.js'
import top from "./top/index.vue"; import top from "./top/index.vue";
import front from "./front/index.vue"; import front from "./front/index.vue";
@ -102,6 +100,10 @@
}, },
beforeDestroy() { beforeDestroy() {
this.clearTypewriterTimers(); this.clearTypewriterTimers();
if (this.isPlayingVoice) {
this.audioContext.stop();
this.isPlayingVoice = false;
}
}, },
methods: { methods: {
// //
@ -144,9 +146,6 @@
}); });
this.audioContext.onEnded(res => { this.audioContext.onEnded(res => {
this.isPlayingVoice = false this.isPlayingVoice = false
const platform = uni.getSystemInfoSync().uniPlatform;
if(platform === 'web') return;
removeFile(this.audioContext.src)
}) })
}, },
// arraybuff // arraybuff
@ -156,39 +155,11 @@
let startTime = Date.now(); let startTime = Date.now();
return new Promise((resolve) => { return new Promise((resolve) => {
textToSpeech(speechStr).then(audioData => { textToSpeech(speechStr).then(audioData => {
let endTime = Date.now(); this.playSrc = audioData;
console.log('语音合成耗时:', endTime - startTime, 'ms'); this.audioContext.src = audioData;
const platform = uni.getSystemInfoSync().uniPlatform;
// H5
if (platform === 'web') {
const blob = new Blob([audioData], {
type: 'audio/mp3'
});
const url = URL.createObjectURL(blob);
this.playSrc = url;
this.audioContext.src = url;
this.textToVoiceLoading = false;
resolve(true)
}
// App
else {
const base64Audio = uni.arrayBufferToBase64(audioData);
const base64WithPrefix = `data:audio/mp3;base64,${base64Audio}`;
const fileName = `_doc/${Date.now()}_numberPerson.mp3`;
base64ToFile(base64WithPrefix, fileName, (path) => {
self.playSrc = path;
self.textToVoiceLoading = false;
self.audioContext.src = path;
let endTime2 = Date.now();
console.log('语音下载到手机耗时:', endTime2 - startTime, 'ms');
resolve(true)
});
}
}).catch(err => {
resolve(true) resolve(true)
}) })
}) })
}, },
// //
refresh() { refresh() {
@ -215,7 +186,6 @@
}, },
// //
handleBreak() { handleBreak() {
console.log('handleBreak');
if (this.isLoading) { if (this.isLoading) {
const loadingIdx = this.messages.findIndex((m) => m.id === this.loadingId); const loadingIdx = this.messages.findIndex((m) => m.id === this.loadingId);
if (loadingIdx > -1) this.messages.splice(loadingIdx, 1); if (loadingIdx > -1) this.messages.splice(loadingIdx, 1);
@ -422,15 +392,16 @@
let content = '' let content = ''
// //
if (reply.errMsg) { if (reply.errMsg) {
content = `请求出错: ${reply.errMsg}` content = `请求出错: 系统异常`
} else { } else {
content = reply; content = reply;
}; };
let result let result;
let speechId = Date.now();
this.speechId = speechId;
if (this.$store.state.set.replyPattern === '1' && !this.messages[this.messages.length - 1].src && ! if (this.$store.state.set.replyPattern === '1' && !this.messages[this.messages.length - 1].src && !
reply.errMsg) { reply.errMsg) {
let speechId = Date.now();
this.speechId = speechId;
result = await this.getSpeech(reply); result = await this.getSpeech(reply);
}; };
if (result) { if (result) {

@ -41,7 +41,7 @@ const request = (config) => {
if (res.success) { if (res.success) {
resolve(res.data); resolve(res.data);
} else { } else {
resolve(res.error); resolve({errMsg : res.error});
} }
}) })
.catch((error) => { .catch((error) => {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 439 B

After

Width:  |  Height:  |  Size: 478 B

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -1 +1 @@
{"@platforms":["android","iPhone","iPad"],"id":"__UNI__5BDEDB4","name":"萃星智能AI","version":{"name":"1.0.1","code":100},"description":"","launch_path":"__uniappview.html","developer":{"name":"","email":"","url":""},"permissions":{"Record":{},"UniNView":{"description":"UniNView原生渲染"}},"plus":{"useragent":{"value":"uni-app","concatenate":true},"splashscreen":{"target":"id:1","autoclose":true,"waiting":true,"delay":0},"popGesture":"close","launchwebview":{"render":"always","id":"1","kernel":"WKWebview"},"statusbar":{"immersed":"supportedDevice","style":"dark","background":"#F8F8F8"},"usingComponents":true,"nvueStyleCompiler":"uni-app","compilerVersion":3,"compatible":{"ignoreVersion":true},"distribute":{"icons":{"android":{"hdpi":"unpackage/res/icons/72x72.png","xhdpi":"unpackage/res/icons/96x96.png","xxhdpi":"unpackage/res/icons/144x144.png","xxxhdpi":"unpackage/res/icons/192x192.png"},"ios":{"appstore":"unpackage/res/icons/1024x1024.png","ipad":{"app":"unpackage/res/icons/76x76.png","app@2x":"unpackage/res/icons/152x152.png","notification":"unpackage/res/icons/20x20.png","notification@2x":"unpackage/res/icons/40x40.png","proapp@2x":"unpackage/res/icons/167x167.png","settings":"unpackage/res/icons/29x29.png","settings@2x":"unpackage/res/icons/58x58.png","spotlight":"unpackage/res/icons/40x40.png","spotlight@2x":"unpackage/res/icons/80x80.png"},"iphone":{"app@2x":"unpackage/res/icons/120x120.png","app@3x":"unpackage/res/icons/180x180.png","notification@2x":"unpackage/res/icons/40x40.png","notification@3x":"unpackage/res/icons/60x60.png","settings@2x":"unpackage/res/icons/58x58.png","settings@3x":"unpackage/res/icons/87x87.png","spotlight@2x":"unpackage/res/icons/80x80.png","spotlight@3x":"unpackage/res/icons/120x120.png"}}},"google":{"permissions":["<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>","<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>","<uses-permission android:name=\"android.permission.VIBRATE\"/>","<uses-permission android:name=\"android.permission.READ_LOGS\"/>","<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>","<uses-feature android:name=\"android.hardware.camera.autofocus\"/>","<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>","<uses-permission android:name=\"android.permission.CAMERA\"/>","<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>","<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>","<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>","<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>","<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>","<uses-feature android:name=\"android.hardware.camera\"/>","<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"],"abiFilters":["armeabi-v7a","arm64-v8a","x86"]},"apple":{"dSYMs":false},"plugins":{"ad":{},"audio":{"mp3":{"description":"Android平台录音支持MP3格式文件"}}}},"uniStatistics":{"enable":false},"allowsInlineMediaPlayback":true,"uni-app":{"compilerVersion":"4.29","control":"uni-v3","nvueCompiler":"uni-app","renderer":"auto","nvue":{"flex-direction":"column"},"nvueLaunchMode":"normal"},"launch_path":"__uniappview.html"}} {"@platforms":["android","iPhone","iPad"],"id":"__UNI__5BDEDB4","name":"萃星智能AI","version":{"name":"1.0.1","code":100},"description":"","launch_path":"__uniappview.html","developer":{"name":"","email":"","url":""},"permissions":{"Record":{},"UniNView":{"description":"UniNView原生渲染"}},"plus":{"useragent":{"value":"uni-app","concatenate":true},"splashscreen":{"target":"id:1","autoclose":true,"waiting":true,"delay":0},"popGesture":"close","launchwebview":{"render":"always","id":"1","kernel":"WKWebview"},"statusbar":{"immersed":"supportedDevice","style":"dark","background":"#F8F8F8"},"usingComponents":true,"nvueStyleCompiler":"uni-app","compilerVersion":3,"compatible":{"ignoreVersion":true},"distribute":{"icons":{"android":{"hdpi":"unpackage/res/icons/72x72.png","xhdpi":"unpackage/res/icons/96x96.png","xxhdpi":"unpackage/res/icons/144x144.png","xxxhdpi":"unpackage/res/icons/192x192.png"},"ios":{"appstore":"unpackage/res/icons/1024x1024.png","ipad":{"app":"unpackage/res/icons/76x76.png","app@2x":"unpackage/res/icons/152x152.png","notification":"unpackage/res/icons/20x20.png","notification@2x":"unpackage/res/icons/40x40.png","proapp@2x":"unpackage/res/icons/167x167.png","settings":"unpackage/res/icons/29x29.png","settings@2x":"unpackage/res/icons/58x58.png","spotlight":"unpackage/res/icons/40x40.png","spotlight@2x":"unpackage/res/icons/80x80.png"},"iphone":{"app@2x":"unpackage/res/icons/120x120.png","app@3x":"unpackage/res/icons/180x180.png","notification@2x":"unpackage/res/icons/40x40.png","notification@3x":"unpackage/res/icons/60x60.png","settings@2x":"unpackage/res/icons/58x58.png","settings@3x":"unpackage/res/icons/87x87.png","spotlight@2x":"unpackage/res/icons/80x80.png","spotlight@3x":"unpackage/res/icons/120x120.png"}}},"splashscreen":{"androidStyle":"common","android":{"hdpi":"static/cxlogo.png"}},"google":{"permissions":["<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>","<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>","<uses-permission android:name=\"android.permission.VIBRATE\"/>","<uses-permission android:name=\"android.permission.READ_LOGS\"/>","<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>","<uses-feature android:name=\"android.hardware.camera.autofocus\"/>","<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>","<uses-permission android:name=\"android.permission.CAMERA\"/>","<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>","<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>","<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>","<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>","<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>","<uses-feature android:name=\"android.hardware.camera\"/>","<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"],"abiFilters":["armeabi-v7a","arm64-v8a","x86"]},"apple":{"dSYMs":false},"plugins":{"ad":{},"audio":{"mp3":{"description":"Android平台录音支持MP3格式文件"}}}},"uniStatistics":{"enable":false},"allowsInlineMediaPlayback":true,"uni-app":{"compilerVersion":"4.29","control":"uni-v3","nvueCompiler":"uni-app","renderer":"auto","nvue":{"flex-direction":"column"},"nvueLaunchMode":"normal"},"launch_path":"__uniappview.html"}}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 350 KiB

After

Width:  |  Height:  |  Size: 122 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.8 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.7 KiB

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

@ -38,76 +38,20 @@ export function copyText(text) {
}); });
}; };
export const removeFile = (filePath) => {
plus.io.resolveLocalFileSystemURL(
filePath,
(entry) => {
entry.remove(
() => console.log("删除成功"), // 成功回调
(error) => console.log(`删除失败:${error.message}`) // 失败回调
);
},
(error) => console.log(`文件不存在:${error.message}`)
);
}
export const base64ToFile = (base64Strs, fileName, callback) => {
let index = base64Strs.indexOf(',');
let base64Str = base64Strs.slice(index + 1, base64Strs.length);
plus.io.requestFileSystem(plus.io.PRIVATE_DOC, function(fs) {
fs.root.getFile(fileName, {
create: true
}, function(entry) {
let fullPath = entry.fullPath;
let platform = uni.getSystemInfoSync().platform;
if (platform == 'android') {
let Base64 = plus.android.importClass("android.util.Base64");
let FileOutputStream = plus.android.importClass("java.io.FileOutputStream");
try {
let out = new FileOutputStream(fullPath);
let bytes = Base64.decode(base64Str, Base64.DEFAULT);
out.write(bytes);
out.close();
callback && callback(entry.toLocalURL());
} catch (e) {
console.log(e.message);
}
} else if (platform == 'ios') {
let NSData = plus.ios.importClass('NSData');
let nsData = new NSData();
nsData = nsData.initWithBase64EncodedStringoptions(base64Str, 0);
if (nsData) {
nsData.plusCallMethod({
writeToFile: fullPath,
atomically: true
});
plus.ios.deleteObject(nsData);
}
callback && callback(entry.toLocalURL());
}
});
});
};
export function textToSpeech(text, options = {}) { export function textToSpeech(text, options = {}) {
return new Promise((resolve, reject) => { return new Promise(async (resolve, reject) => {
const { const {
token = '24.1c8cc30b5f7be445723b6d4b19a36152.2592000.1765094496.282335-120706844', token = '24.1c8cc30b5f7be445723b6d4b19a36152.2592000.1765094496.282335-120706844',
tex = text, tex = text,
cuid = 'uni-app-demo', cuid = 'uni-app-demo',
ctp = 1, ctp = 1,
lan = 'zh', lan = 'zh',
spd = 5, spd = 5,
pit = 5, pit = 5,
vol = 5, vol = 5,
per = 0 per = 0
} = options } = options
const url = 'https://tsn.baidu.com/text2audio' const url = 'https://tsn.baidu.com/text2audio'
const params = { const params = {
tex: encodeURIComponent(tex), tex: encodeURIComponent(tex),
@ -120,47 +64,19 @@ export function textToSpeech(text, options = {}) {
per, per,
tok: token tok: token
} }
// 构建查询字符串 // 构建查询字符串
const queryString = Object.keys(params).map(key => { const queryString = Object.keys(params).map(key => {
return `${key}=${params[key]}` return `${key}=${params[key]}`
}).join('&') }).join('&');
const platform = uni.getSystemInfoSync().uniPlatform;
uni.request({ const result = await uni.downloadFile({
url: `${url}?${queryString}`, url: `${url}?${queryString}`
method: 'GET', });
responseType: 'arraybuffer',
success: (res) => { resolve(result.tempFilePath);
// 检查响应状态
if (res.statusCode === 200) {
// 检查是否是音频数据MP3格式通常以特定字节开头
if (res.data && res.data.byteLength > 0) {
// 检查是否是JSON错误响应百度API错误时返回JSON
try {
const textDecoder = new TextDecoder('utf-8')
const text = textDecoder.decode(new Uint8Array(res.data.slice(0, 100)))
if (text.startsWith('{') || text.startsWith('[')) {
// 是JSON响应说明是错误
const errorData = JSON.parse(text)
console.error('TTS API Error:', errorData)
reject(new Error(errorData.err_msg || 'TTS请求失败'))
return
}
} catch (e) {
// 不是JSON应该是音频数据
}
resolve(res.data)
} else {
reject(new Error('返回数据为空'))
}
} else {
reject(new Error(`请求失败,状态码: ${res.statusCode}`))
}
},
fail: (err) => {
console.error('TTS Request Error:', err)
reject(new Error(err.errMsg || '网络请求失败'))
}
})
}) })
} }
Loading…
Cancel
Save