Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
glsx
/
gl_tape
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
3
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit e8ff93d3
authored
Jun 26, 2026
by
岑成威
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix: 日志冲突
1 parent
668dc98c
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
85 additions
and
19 deletions
components/AiAssistantBall/AiAssistantBall.vue
uni_modules/uni-recorder-x/utssdk/app-android/AudioRecorder.kt
uni_modules/uni-recorder-x/utssdk/app-android/index.uts
uni_modules/uni-recorder-x/utssdk/app-android/utils.uts
uni_modules/uni-recorder-x/utssdk/app-ios/UniAudioRecorderManager.swift
utils/recordManager/AudioManager.js
utils/recordManager/FileUploadManager.js
utils/recordManager/NativeSave.js
utils/recordManager/PollingSave.js
utils/recordManager/RecordSaveService.js
utils/recordManager/RecordService.js
utils/recordManager/TempRecord.js
utils/recordManager/helpler.js
components/AiAssistantBall/AiAssistantBall.vue
View file @
e8ff93d
...
@@ -30,14 +30,14 @@
...
@@ -30,14 +30,14 @@
<view
class=
"fab-content-idle"
>
<view
class=
"fab-content-idle"
>
<image
<image
class=
"idle-mascot-svg"
class=
"idle-mascot-svg"
src=
"
https://img02.glsx.com.cn/weapp/resource/app-tape
/ai-assistant/side-sparkle-rise-export.svg"
src=
"
/static/images
/ai-assistant/side-sparkle-rise-export.svg"
mode=
"scaleToFill"
mode=
"scaleToFill"
></image>
></image>
</view>
</view>
<view
class=
"fab-content-active"
>
<view
class=
"fab-content-active"
>
<image
<image
class=
"thinking-orb-svg"
class=
"thinking-orb-svg"
src=
"
https://img02.glsx.com.cn/weapp/resource/app-tape
/ai-assistant/122-eye-blink.svg"
src=
"
/static/images
/ai-assistant/122-eye-blink.svg"
mode=
"scaleToFill"
mode=
"scaleToFill"
></image>
></image>
<!--
<view
class=
"thinking-capsule-bg"
></view>
-->
<!--
<view
class=
"thinking-capsule-bg"
></view>
-->
...
@@ -70,7 +70,7 @@
...
@@ -70,7 +70,7 @@
<text
class=
"help-menu-action-text"
>
✨ 帮我回答顾客刚才的问题(近1分钟)
</text>
<text
class=
"help-menu-action-text"
>
✨ 帮我回答顾客刚才的问题(近1分钟)
</text>
<image
<image
class=
"help-menu-action-arrow"
class=
"help-menu-action-arrow"
src=
"
https://img02.glsx.com.cn/weapp/resource/app-tape
/ai-assistant/Vector.png"
src=
"
/static/images
/ai-assistant/Vector.png"
mode=
"aspectFit"
mode=
"aspectFit"
/>
/>
</view>
</view>
...
@@ -78,7 +78,7 @@
...
@@ -78,7 +78,7 @@
<text
class=
"help-menu-action-text"
>
🌟 介绍下谈客助手该如何使用
</text>
<text
class=
"help-menu-action-text"
>
🌟 介绍下谈客助手该如何使用
</text>
<image
<image
class=
"help-menu-action-arrow"
class=
"help-menu-action-arrow"
src=
"
https://img02.glsx.com.cn/weapp/resource/app-tape
/ai-assistant/Vector.png"
src=
"
/static/images
/ai-assistant/Vector.png"
mode=
"aspectFit"
mode=
"aspectFit"
/>
/>
</view>
</view>
...
@@ -132,7 +132,7 @@
...
@@ -132,7 +132,7 @@
<text
class=
"help-menu-action-text"
>
🌟
{{
item
.
query
}}
</text>
<text
class=
"help-menu-action-text"
>
🌟
{{
item
.
query
}}
</text>
<image
<image
class=
"help-menu-action-arrow"
class=
"help-menu-action-arrow"
src=
"
https://img02.glsx.com.cn/weapp/resource/app-tape
/ai-assistant/Vector.png"
src=
"
/static/images
/ai-assistant/Vector.png"
mode=
"aspectFit"
mode=
"aspectFit"
/>
/>
</view>
</view>
...
@@ -1423,7 +1423,7 @@ export default {
...
@@ -1423,7 +1423,7 @@ export default {
}
}
.result-head.question-content-head
{
.result-head.question-content-head
{
height
:
53px
;
height
:
53px
;
padding
:
16px
24px
;
padding
:
28px
24px
16px
24px
;
align-items
:
center
;
align-items
:
center
;
flex-shrink
:
0
;
flex-shrink
:
0
;
}
}
...
...
uni_modules/uni-recorder-x/utssdk/app-android/AudioRecorder.kt
View file @
e8ff93d
...
@@ -49,6 +49,7 @@ class AudioRecorder() {
...
@@ -49,6 +49,7 @@ class AudioRecorder() {
// 定义错误码常量
// 定义错误码常量
companion
object
{
companion
object
{
private
const
val
TAG
=
"uni-recorder-x"
const
val
ERROR_RECORDING_IN_PROGRESS
=
1001
const
val
ERROR_RECORDING_IN_PROGRESS
=
1001
const
val
ERROR_NO_SUPPORTED_SAMPLE_RATE
=
1107602
const
val
ERROR_NO_SUPPORTED_SAMPLE_RATE
=
1107602
const
val
ERROR_BUFFER_SIZE_CALCULATION_FAILED
=
1107603
const
val
ERROR_BUFFER_SIZE_CALCULATION_FAILED
=
1107603
...
@@ -151,7 +152,7 @@ class AudioRecorder() {
...
@@ -151,7 +152,7 @@ class AudioRecorder() {
}
else
{
}
else
{
this
.
filePath
=
null
this
.
filePath
=
null
}
}
Log
.
d
(
"AudioRecorder"
,
"File path set to:
$filePath"
)
Log
.
i
(
TAG
,
"startRecording: format=$format, saveToFile=$saveToFile, path=
$filePath"
)
// 检测并调整采样率
// 检测并调整采样率
...
@@ -286,6 +287,7 @@ class AudioRecorder() {
...
@@ -286,6 +287,7 @@ class AudioRecorder() {
}
}
}
}
}
catch
(
e
:
IOException
)
{
}
catch
(
e
:
IOException
)
{
Log
.
e
(
TAG
,
"write failed: path=$filePath, ${e.message}"
)
notifyError
(
ERROR_FILE_WRITE_FAILED
,
"录音过程中写入文件出错: ${e.message}"
)
notifyError
(
ERROR_FILE_WRITE_FAILED
,
"录音过程中写入文件出错: ${e.message}"
)
}
finally
{
}
finally
{
// 清理资源
// 清理资源
...
@@ -554,6 +556,10 @@ class AudioRecorder() {
...
@@ -554,6 +556,10 @@ class AudioRecorder() {
}
}
audioRecord
=
null
audioRecord
=
null
val
savedPath
=
filePath
val
fileSize
=
savedPath
?.
let
{
File
(
it
).
takeIf
{
f
->
f
.
exists
()
}
?.
length
()
}
?:
-
1L
Log
.
i
(
TAG
,
"stopRecording: path=$savedPath, size=$fileSize bytes"
)
mainHandler
.
post
{
mainHandler
.
post
{
recordingListener
?.
onRecordingStopped
()
recordingListener
?.
onRecordingStopped
()
}
}
...
...
uni_modules/uni-recorder-x/utssdk/app-android/index.uts
View file @
e8ff93d
...
@@ -8,6 +8,8 @@ import Base64 from "android.util.Base64";
...
@@ -8,6 +8,8 @@ import Base64 from "android.util.Base64";
export { RecorderManagerFailImpl }
export { RecorderManagerFailImpl }
const LOG_TAG = '[uni-recorder-x]'
// NOTE 避免被 vue Proxy 污染
// NOTE 避免被 vue Proxy 污染
const DEFAULT_DURATION = 1000 * 60
const DEFAULT_DURATION = 1000 * 60
const MAX_DURATION = DEFAULT_DURATION * 10
const MAX_DURATION = DEFAULT_DURATION * 10
...
@@ -75,7 +77,9 @@ class RecorderManagerImpl implements RecorderManager, RecordingListener, AudioDa
...
@@ -75,7 +77,9 @@ class RecorderManagerImpl implements RecorderManager, RecordingListener, AudioDa
this.manager.setRecordingListener(this)
this.manager.setRecordingListener(this)
this.manager.setAudioDataListener(this)
this.manager.setAudioDataListener(this)
this.manager.setMaxRecordingDuration(options.duration!.toLong())
this.manager.setMaxRecordingDuration(options.duration!.toLong())
this.manager.startRecording(format, createFile(options.format! as string, options.saveDir))
const filePath = createFile(options.format! as string, options.saveDir)
console.log(`${LOG_TAG} start: format=${options.format}, sampleRate=${options.sampleRate}, channels=${options.numberOfChannels}, filePath=${filePath}`)
this.manager.startRecording(format, filePath)
}
}
// override pause() : void {
// override pause() : void {
// this.manager.pauseRecording()
// this.manager.pauseRecording()
...
@@ -84,6 +88,7 @@ class RecorderManagerImpl implements RecorderManager, RecordingListener, AudioDa
...
@@ -84,6 +88,7 @@ class RecorderManagerImpl implements RecorderManager, RecordingListener, AudioDa
// this.manager.resumeRecording()
// this.manager.resumeRecording()
// }
// }
override stop() {
override stop() {
console.log(`${LOG_TAG} stop: filePath=${this.manager.getFilePath()}`)
this.manager.stopRecording()
this.manager.stopRecording()
}
}
...
@@ -151,11 +156,15 @@ class RecorderManagerImpl implements RecorderManager, RecordingListener, AudioDa
...
@@ -151,11 +156,15 @@ class RecorderManagerImpl implements RecorderManager, RecordingListener, AudioDa
// }
// }
override onRecordingStarted() {
override onRecordingStarted() {
let res = new RecorderManagerOnStartResultCallback(this.manager.getFilePath()!)
const filePath = this.manager.getFilePath()!
console.log(`${LOG_TAG} onStart: filePath=${filePath}`)
let res = new RecorderManagerOnStartResultCallback(filePath)
this.startCallback?.(res)
this.startCallback?.(res)
}
}
override onRecordingStopped() {
override onRecordingStopped() {
this.stopCallback?.(new RecorderManagerOnStopResultCallback(this.manager.getFilePath()!))
const filePath = this.manager.getFilePath()!
console.log(`${LOG_TAG} onStop: filePath=${filePath}`)
this.stopCallback?.(new RecorderManagerOnStopResultCallback(filePath))
}
}
override onRecordingPaused() {
override onRecordingPaused() {
// this.pauseCallback?.("")
// this.pauseCallback?.("")
...
@@ -164,6 +173,7 @@ class RecorderManagerImpl implements RecorderManager, RecordingListener, AudioDa
...
@@ -164,6 +173,7 @@ class RecorderManagerImpl implements RecorderManager, RecordingListener, AudioDa
// this.resumeCallback?.("")
// this.resumeCallback?.("")
}
}
override onRecordingError(errorCode : Int, errorMessage : String) {
override onRecordingError(errorCode : Int, errorMessage : String) {
console.log(`${LOG_TAG} onError: code=${errorCode}, msg=${errorMessage}`)
var error : IRecorderManagerFail
var error : IRecorderManagerFail
if ([1107601, 1107602, 1107603, 1107604, 1107605, 1107606, 1107607, 1107608].indexOf(errorCode) >= 0) {
if ([1107601, 1107602, 1107603, 1107604, 1107605, 1107606, 1107607, 1107608].indexOf(errorCode) >= 0) {
error = new RecorderManagerFailImpl(errorCode, RecorderManagerUniErrors[errorCode]!)
error = new RecorderManagerFailImpl(errorCode, RecorderManagerUniErrors[errorCode]!)
...
...
uni_modules/uni-recorder-x/utssdk/app-android/utils.uts
View file @
e8ff93d
...
@@ -11,10 +11,13 @@ export interface StateChangeRes extends RecorderManagerOnStopResult {
...
@@ -11,10 +11,13 @@ export interface StateChangeRes extends RecorderManagerOnStopResult {
export function onRecorderStateChange(state : RecorderState, res ?: StateChangeRes) : void {
export function onRecorderStateChange(state : RecorderState, res ?: StateChangeRes) : void {
}
}
const LOG_TAG = '[uni-recorder-x]'
export function createFile( format : string, saveDir ?: string | null) : string {
export function createFile( format : string, saveDir ?: string | null) : string {
var dirPath : string
var dirPath : string
if (saveDir != null && saveDir!.length > 0) {
if (saveDir != null && saveDir!.length > 0) {
dirPath = saveDir!
dirPath = saveDir!
console.log(`${LOG_TAG} createFile: 使用自定义目录 saveDir=${saveDir}`)
} else {
} else {
let context = UTSAndroid.getAppContext()
let context = UTSAndroid.getAppContext()
var parentPath = UTSAndroid.getAppCachePath()
var parentPath = UTSAndroid.getAppCachePath()
...
@@ -33,6 +36,8 @@ export function createFile( format : string, saveDir ?: string | null) : string
...
@@ -33,6 +36,8 @@ export function createFile( format : string, saveDir ?: string | null) : string
}
}
const random = UUID.randomUUID().toString().replace(/-/g, '').substring(0, 8)
const random = UUID.randomUUID().toString().replace(/-/g, '').substring(0, 8)
const fileName = `${Date.now()}_${random}.${format.toLocaleLowerCase()}`
const fileName = `${Date.now()}_${random}.${format.toLocaleLowerCase()}`
return `${dir.path}/${fileName}`
const filePath = `${dir.path}/${fileName}`
console.log(`${LOG_TAG} createFile: 生成录音文件 path=${filePath}`)
return filePath
}
}
export const supportFormats = ['aac']
export const supportFormats = ['aac']
uni_modules/uni-recorder-x/utssdk/app-ios/UniAudioRecorderManager.swift
View file @
e8ff93d
...
@@ -67,6 +67,7 @@ typealias UniAudioRecorderErrorEventCallback = (_ result: IRecorderManagerFail)
...
@@ -67,6 +67,7 @@ typealias UniAudioRecorderErrorEventCallback = (_ result: IRecorderManagerFail)
public
class
UniAudioRecorderManager
:
NSObject
,
RecorderManager
{
public
class
UniAudioRecorderManager
:
NSObject
,
RecorderManager
{
public
static
var
shared
=
UniAudioRecorderManager
()
public
static
var
shared
=
UniAudioRecorderManager
()
private
let
logTag
=
"[uni-recorder-x]"
private
var
audioRecorder
:
AVAudioRecorder
?
private
var
audioRecorder
:
AVAudioRecorder
?
...
@@ -150,6 +151,7 @@ public class UniAudioRecorderManager: NSObject, RecorderManager {
...
@@ -150,6 +151,7 @@ public class UniAudioRecorderManager: NSObject, RecorderManager {
public
func
stop
()
{
public
func
stop
()
{
if
let
isRecording
=
audioRecorder
?
.
isRecording
,
(
isRecording
||
isPaused
)
{
if
let
isRecording
=
audioRecorder
?
.
isRecording
,
(
isRecording
||
isPaused
)
{
let
savedPath
=
audioRecorder
?
.
url
.
path
??
""
audioRecorder
?
.
stop
()
audioRecorder
?
.
stop
()
stopDisplayLink
()
stopDisplayLink
()
...
@@ -157,7 +159,8 @@ public class UniAudioRecorderManager: NSObject, RecorderManager {
...
@@ -157,7 +159,8 @@ public class UniAudioRecorderManager: NSObject, RecorderManager {
result
.
tempFilePath
=
audioRecorder
?
.
url
.
absoluteString
??
""
result
.
tempFilePath
=
audioRecorder
?
.
url
.
absoluteString
??
""
dispatchStopEvent
(
event
:
.
stop
,
result
:
result
)
dispatchStopEvent
(
event
:
.
stop
,
result
:
result
)
print
(
"录音已完成,文件保存在:
\(
audioRecorder
?
.
url
.
absoluteString
??
"未知路径"
)
"
)
let
fileSize
=
(
try
?
FileManager
.
default
.
attributesOfItem
(
atPath
:
savedPath
)[
.
size
]
as?
Int64
)
??
-
1
print
(
"
\(
logTag
)
stop: path=
\(
savedPath
)
, size=
\(
fileSize
)
bytes"
)
audioRecorder
=
nil
audioRecorder
=
nil
}
}
}
}
...
@@ -292,6 +295,7 @@ extension UniAudioRecorderManager {
...
@@ -292,6 +295,7 @@ extension UniAudioRecorderManager {
]
]
let
fileURL
=
getAudioRecorderFileURL
()
let
fileURL
=
getAudioRecorderFileURL
()
print
(
"
\(
logTag
)
start: format=
\(
audioFormat
.
rawValue
)
, sampleRate=
\(
sampleRate
)
, channels=
\(
channels
)
, path=
\(
fileURL
.
path
)
"
)
audioRecorder
=
try
AVAudioRecorder
(
url
:
fileURL
,
settings
:
settings
)
audioRecorder
=
try
AVAudioRecorder
(
url
:
fileURL
,
settings
:
settings
)
audioRecorder
?
.
delegate
=
self
audioRecorder
?
.
delegate
=
self
audioRecorder
?
.
isMeteringEnabled
=
true
audioRecorder
?
.
isMeteringEnabled
=
true
...
@@ -328,7 +332,7 @@ extension UniAudioRecorderManager {
...
@@ -328,7 +332,7 @@ extension UniAudioRecorderManager {
}
catch
{
}
catch
{
failedAction
(
1107604
,
errMsg
:
error
.
localizedDescription
)
failedAction
(
1107604
,
errMsg
:
error
.
localizedDescription
)
print
(
"
录音启动失败
:
\(
error
.
localizedDescription
)
"
)
print
(
"
\(
logTag
)
start failed
:
\(
error
.
localizedDescription
)
"
)
}
}
}
}
...
@@ -363,7 +367,9 @@ extension UniAudioRecorderManager {
...
@@ -363,7 +367,9 @@ extension UniAudioRecorderManager {
}
}
let
random
=
UUID
()
.
uuidString
.
replacingOccurrences
(
of
:
"-"
,
with
:
""
)
.
prefix
(
8
)
let
random
=
UUID
()
.
uuidString
.
replacingOccurrences
(
of
:
"-"
,
with
:
""
)
.
prefix
(
8
)
let
fileName
=
Date
()
.
timeIntervalSince1970
.
toString
()
+
"_"
+
random
+
"."
+
suffixName
let
fileName
=
Date
()
.
timeIntervalSince1970
.
toString
()
+
"_"
+
random
+
"."
+
suffixName
return
recordPath
.
appendingPathComponent
(
fileName
)
let
fileURL
=
recordPath
.
appendingPathComponent
(
fileName
)
print
(
"
\(
logTag
)
createFile: path=
\(
fileURL
.
path
)
"
)
return
fileURL
}
}
private
func
ensureDirExist
(
_
path
:
String
)
{
private
func
ensureDirExist
(
_
path
:
String
)
{
...
...
utils/recordManager/AudioManager.js
View file @
e8ff93d
...
@@ -39,6 +39,7 @@ class AudioManager {
...
@@ -39,6 +39,7 @@ class AudioManager {
onFrameRecordedEnd
,
onFrameRecordedEnd
,
}
}
this
.
startOptions
.
saveDir
=
saveDir
this
.
startOptions
.
saveDir
=
saveDir
uni
.
$logger
.
local
.
info
(
`【接待录音】AudioManager初始化: saveDir=
${
saveDir
}
`
)
}
}
on
()
{
on
()
{
// 使用策略工厂获取录音管理器实例
// 使用策略工厂获取录音管理器实例
...
@@ -57,6 +58,7 @@ class AudioManager {
...
@@ -57,6 +58,7 @@ class AudioManager {
* 此方法用于初始化录音过程,它将配置参数应用到录音管理器,并开始录音
* 此方法用于初始化录音过程,它将配置参数应用到录音管理器,并开始录音
*/
*/
start
()
{
start
()
{
uni
.
$logger
.
local
.
info
(
`【接待录音】开启录音: saveDir=
${
this
.
startOptions
.
saveDir
}
, format=
${
this
.
startOptions
.
format
}
`
)
uni
.
$logger
.
local
.
info
(
'〖录音管理Audio〗 == 开启录音 '
)
uni
.
$logger
.
local
.
info
(
'〖录音管理Audio〗 == 开启录音 '
)
this
.
recorderManager
.
start
(
this
.
startOptions
)
this
.
recorderManager
.
start
(
this
.
startOptions
)
}
}
...
@@ -100,6 +102,8 @@ class AudioManager {
...
@@ -100,6 +102,8 @@ class AudioManager {
* 然后调用events对象上的onStop方法处理具体的停止录音逻辑
* 然后调用events对象上的onStop方法处理具体的停止录音逻辑
*/
*/
async
onStop
(
res
)
{
async
onStop
(
res
)
{
const
filePath
=
res
?.
tempFilePath
||
res
?.
filePath
||
''
uni
.
$logger
.
local
.
info
(
`【接待录音】停止录音回调: filePath=
${
filePath
}
`
)
uni
.
$logger
.
local
.
info
(
'〖录音管理Audio〗 == 停止录音回调 '
)
uni
.
$logger
.
local
.
info
(
'〖录音管理Audio〗 == 停止录音回调 '
)
await
this
.
events
.
onStop
(
res
)
await
this
.
events
.
onStop
(
res
)
}
}
...
...
utils/recordManager/FileUploadManager.js
View file @
e8ff93d
...
@@ -187,6 +187,8 @@ class FileUploadManager {
...
@@ -187,6 +187,8 @@ class FileUploadManager {
*/
*/
async
uploadRecord
(
record
,
callback
)
{
async
uploadRecord
(
record
,
callback
)
{
try
{
try
{
const
fullPath
=
(
record
.
filePath
||
''
)
+
(
record
.
fileName
||
''
)
uni
.
$logger
.
local
.
info
(
`【接待录音】上传前: recordId=
${
record
.
recordId
}
, fullPath=
${
fullPath
}
, status=
${
record
.
status
}
`
)
uni
.
$logger
.
local
.
info
(
`[FileUploadManager] 开始上传文件:
${
record
.
fileName
}
`
)
uni
.
$logger
.
local
.
info
(
`[FileUploadManager] 开始上传文件:
${
record
.
fileName
}
`
)
// 处理无文件或文件不存在的情况
// 处理无文件或文件不存在的情况
if
(
record
.
status
===
FileStatus
.
NoFile
||
record
.
status
===
FileStatus
.
NotExist
)
{
if
(
record
.
status
===
FileStatus
.
NoFile
||
record
.
status
===
FileStatus
.
NotExist
)
{
...
...
utils/recordManager/NativeSave.js
View file @
e8ff93d
...
@@ -20,11 +20,14 @@ class NativeSave extends TempRecord {
...
@@ -20,11 +20,14 @@ class NativeSave extends TempRecord {
* @returns {Promise<void>}
* @returns {Promise<void>}
*/
*/
async
add
(
audio
)
{
async
add
(
audio
)
{
const
filePath
=
audio
?.
filePath
||
audio
?.
tempFilePath
||
''
uni
.
$logger
.
local
.
info
(
`【接待录音】NativeSave.add: filePath=
${
filePath
}
`
)
uni
.
$logger
.
local
.
info
(
'〖NativeSave〗 == add called with: '
+
audio
?.
filePath
)
uni
.
$logger
.
local
.
info
(
'〖NativeSave〗 == add called with: '
+
audio
?.
filePath
)
// 创建一个新的记录对象
// 创建一个新的记录对象
const
recordUrlList
=
audio
&&
audio
.
filePath
?
[{
file
:
audio
.
filePath
}]
:
[]
const
recordUrlList
=
audio
&&
audio
.
filePath
?
[{
file
:
audio
.
filePath
}]
:
[]
// 调用基类通用流程
// 调用基类通用流程
await
super
.
add
(
recordUrlList
)
await
super
.
add
(
recordUrlList
)
uni
.
$logger
.
local
.
info
(
`【接待录音】NativeSave.add完成: recordId=
${
this
.
record
?.
id
},
fileCount
=
$
{
this
.
record
?.
recordUrlList
?.
length
||
0
}
`)
}
}
}
}
...
...
utils/recordManager/PollingSave.js
View file @
e8ff93d
...
@@ -42,6 +42,7 @@ class PollingSave extends TempRecord {
...
@@ -42,6 +42,7 @@ class PollingSave extends TempRecord {
// 0. 记录旧路径到实例属性,供底层查找时排除
// 0. 记录旧路径到实例属性,供底层查找时排除
this
.
_excludePath
=
this
.
record
?.
tempFilePath
||
''
this
.
_excludePath
=
this
.
record
?.
tempFilePath
||
''
uni
.
$logger
.
local
.
info
(
`【接待录音】addAudio开始: recordId=
${
this
.
record
?.
id
||
''
},
excludePath
=
$
{
this
.
_excludePath
}
`)
// 1. 处理旧录音,并获取清理任务 (只更新内存,不更新数据库)
// 1. 处理旧录音,并获取清理任务 (只更新内存,不更新数据库)
let cleanupTask
let cleanupTask
...
@@ -256,11 +257,11 @@ class PollingSave extends TempRecord {
...
@@ -256,11 +257,11 @@ class PollingSave extends TempRecord {
saveResultPath = saveResult?.savedFilePath
saveResultPath = saveResult?.savedFilePath
}
}
if (!saveResultPath) {
if (!saveResultPath) {
uni.$logger.local.error(`【接待录音】持久化失败,路径为空: src=${tempFilePath}`)
uni.$logger.local.error('
〖接待记录
Record
〗
==
保存文件失败,路径为空
')
uni.$logger.local.error('
〖接待记录
Record
〗
==
保存文件失败,路径为空
')
return
return
}
}
// 减少日志输出,仅在调试需要时开启
uni.$logger.local.info(`【接待录音】持久化临时文件: ${tempFilePath} -> ${saveResultPath}`)
// uni.$logger.local.info('〖接待记录Record〗 == 保存后的文件路径 saveResultPath ->' + saveResultPath)
return saveResultPath
return saveResultPath
} catch (e) {
} catch (e) {
uni.$logger.local.error('
〖接待记录
Record
〗
==
保存文件异常
:
' + e.message)
uni.$logger.local.error('
〖接待记录
Record
〗
==
保存文件异常
:
' + e.message)
...
...
utils/recordManager/RecordSaveService.js
View file @
e8ff93d
...
@@ -367,6 +367,7 @@ class RecordSaveService {
...
@@ -367,6 +367,7 @@ class RecordSaveService {
const
{
status
,
tempFilePath
,
recordStatus
,
...
record
}
=
data
const
{
status
,
tempFilePath
,
recordStatus
,
...
record
}
=
data
const
fileList
=
Array
.
isArray
(
record
.
recordUrlList
)
?
record
.
recordUrlList
:
[]
const
fileList
=
Array
.
isArray
(
record
.
recordUrlList
)
?
record
.
recordUrlList
:
[]
const
isAllCompleted
=
status
===
FileStatus
.
NoFile
||
fileList
.
every
(
i
=>
[
FileStatus
.
Uploaded
,
FileStatus
.
Completed
].
includes
(
i
.
status
))
const
isAllCompleted
=
status
===
FileStatus
.
NoFile
||
fileList
.
every
(
i
=>
[
FileStatus
.
Uploaded
,
FileStatus
.
Completed
].
includes
(
i
.
status
))
uni
.
$logger
.
local
.
info
(
`【接待录音】更新记录状态: recordId=
${
record
.
id
}
, isAllCompleted=
${
isAllCompleted
}
, fileCount=
${
fileList
.
length
}
`
)
if
(
isAllCompleted
)
{
if
(
isAllCompleted
)
{
await
this
.
_handleCompletedRecord
(
record
,
fileList
)
await
this
.
_handleCompletedRecord
(
record
,
fileList
)
}
else
{
}
else
{
...
@@ -472,6 +473,7 @@ class RecordSaveService {
...
@@ -472,6 +473,7 @@ class RecordSaveService {
continue
continue
}
}
if
(
recordUrlList
.
length
==
0
)
{
if
(
recordUrlList
.
length
==
0
)
{
uni
.
$logger
.
local
.
warn
(
`【接待录音】记录无语音文件: recordId=
${
cur
.
id
}
`
)
this
.
_addToBlackList
(
cur
.
id
,
'无语音文件'
)
this
.
_addToBlackList
(
cur
.
id
,
'无语音文件'
)
result
.
push
({
status
:
FileStatus
.
NoFile
,
recordId
:
cur
.
id
})
result
.
push
({
status
:
FileStatus
.
NoFile
,
recordId
:
cur
.
id
})
continue
continue
...
@@ -485,6 +487,7 @@ class RecordSaveService {
...
@@ -485,6 +487,7 @@ class RecordSaveService {
const
file2Up
=
{
...
file
,
recordId
:
cur
.
id
,
fileName
,
filePath
}
const
file2Up
=
{
...
file
,
recordId
:
cur
.
id
,
fileName
,
filePath
}
const
fileExists
=
await
this
.
checkFileExists
(
file
.
file
)
const
fileExists
=
await
this
.
checkFileExists
(
file
.
file
)
if
(
!
fileExists
)
{
if
(
!
fileExists
)
{
uni
.
$logger
.
local
.
warn
(
`【接待录音】文件不存在: recordId=
${
cur
.
id
}
, file=
${
file
.
file
}
`
)
this
.
reportError
(
'【接待记录保存服务】 == 记录中有语音文件地址,但是文件不存在'
,
{
record
:
cur
,
file
},
cur
.
id
,
file
.
file
)
this
.
reportError
(
'【接待记录保存服务】 == 记录中有语音文件地址,但是文件不存在'
,
{
record
:
cur
,
file
},
cur
.
id
,
file
.
file
)
file2Up
.
status
=
FileStatus
.
NotExist
file2Up
.
status
=
FileStatus
.
NotExist
}
}
...
@@ -551,6 +554,7 @@ class RecordSaveService {
...
@@ -551,6 +554,7 @@ class RecordSaveService {
}
}
this
.
_taskStartTime
=
Date
.
now
()
this
.
_taskStartTime
=
Date
.
now
()
this
.
_currentKey
=
this
.
_getTaskKey
(
record
.
recordId
,
record
.
fileName
)
this
.
_currentKey
=
this
.
_getTaskKey
(
record
.
recordId
,
record
.
fileName
)
uni
.
$logger
.
local
.
info
(
`【接待录音】开始上传任务: recordId=
${
record
.
recordId
}
, file=
${
record
.
filePath
}${
record
.
fileName
}
, status=
${
record
.
status
}
`
)
try
{
try
{
if
(
this
.
_isInBlackList
(
record
.
recordId
))
{
if
(
this
.
_isInBlackList
(
record
.
recordId
))
{
uni
.
$logger
.
local
.
warn
(
`【接待记录保存服务】 == 任务在黑名单中,跳过:
${
this
.
_currentKey
}
`
)
uni
.
$logger
.
local
.
warn
(
`【接待记录保存服务】 == 任务在黑名单中,跳过:
${
this
.
_currentKey
}
`
)
...
@@ -655,6 +659,7 @@ class RecordSaveService {
...
@@ -655,6 +659,7 @@ class RecordSaveService {
// 从队列取出任务
// 从队列取出任务
record
=
this
.
snapshot
.
dequeue
()
record
=
this
.
snapshot
.
dequeue
()
uni
.
$logger
.
local
.
info
(
`【接待录音】出队:
${
record
?
`recordId=
${
record
.
recordId
}
, file=
${
record
.
filePath
||
''
}${
record
.
fileName
||
''
}
`
:
'空'
}
`
)
// 执行任务
// 执行任务
await
this
.
beginTask
(
record
)
await
this
.
beginTask
(
record
)
...
...
utils/recordManager/RecordService.js
View file @
e8ff93d
...
@@ -44,6 +44,7 @@ class RecordService {
...
@@ -44,6 +44,7 @@ class RecordService {
try
{
try
{
uni
.
$logger
.
local
.
info
(
'【录音服务RecordService】 == 初始化'
)
uni
.
$logger
.
local
.
info
(
'【录音服务RecordService】 == 初始化'
)
const
saveDir
=
await
PathUtils
.
getFilePath
()
const
saveDir
=
await
PathUtils
.
getFilePath
()
uni
.
$logger
.
local
.
info
(
`【接待录音】初始化: saveDir=
${
saveDir
}
`
)
this
.
audioManager
=
new
AudioManager
(
this
.
onAudioStart
.
bind
(
this
),
this
.
onAudioStop
.
bind
(
this
),
this
.
onAudioError
.
bind
(
this
),
this
.
onFrameRecorded
.
bind
(
this
),
this
.
onFrameRecordedEnd
.
bind
(
this
),
saveDir
)
this
.
audioManager
=
new
AudioManager
(
this
.
onAudioStart
.
bind
(
this
),
this
.
onAudioStop
.
bind
(
this
),
this
.
onAudioError
.
bind
(
this
),
this
.
onFrameRecorded
.
bind
(
this
),
this
.
onFrameRecordedEnd
.
bind
(
this
),
saveDir
)
this
.
initDto
()
this
.
initDto
()
this
.
record
=
StrategyFactory
.
getSaveStrategy
(
this
.
tempRecord
,
this
.
triggerTempNumber
.
bind
(
this
),
this
.
attributesProvider
.
bind
(
this
))
this
.
record
=
StrategyFactory
.
getSaveStrategy
(
this
.
tempRecord
,
this
.
triggerTempNumber
.
bind
(
this
),
this
.
attributesProvider
.
bind
(
this
))
...
@@ -154,6 +155,9 @@ class RecordService {
...
@@ -154,6 +155,9 @@ class RecordService {
async
onAudioStart
(
res
)
{
async
onAudioStart
(
res
)
{
try
{
try
{
const
filePath
=
res
?.
filePath
||
res
?.
tempFilePath
||
''
const
recordId
=
this
.
record
?.
currentRecord
?.
id
||
''
uni
.
$logger
.
local
.
info
(
`【接待录音】onAudioStart: counter=
${
this
.
audioManager
.
counter
}
, recordId=
${
recordId
||
'待创建'
}
, filePath=
${
filePath
}
`
)
// 重置帧缓冲池,开始新的录音周期
// 重置帧缓冲池,开始新的录音周期
this
.
framePool
.
reset
()
this
.
framePool
.
reset
()
...
@@ -162,6 +166,7 @@ class RecordService {
...
@@ -162,6 +166,7 @@ class RecordService {
await
this
.
record
.
add
(
res
)
await
this
.
record
.
add
(
res
)
uni
.
$logger
.
local
.
info
(
'〖RecordService〗 == Record added successfully.'
)
uni
.
$logger
.
local
.
info
(
'〖RecordService〗 == Record added successfully.'
)
}
else
{
}
else
{
uni
.
$logger
.
local
.
info
(
`【接待录音】续录分段: counter=
${
this
.
audioManager
.
counter
}
, filePath=
${
filePath
}
`
)
this
.
record
.
addAudio
(
res
)
this
.
record
.
addAudio
(
res
)
}
}
// setTimeout(() => {
// setTimeout(() => {
...
@@ -175,9 +180,11 @@ class RecordService {
...
@@ -175,9 +180,11 @@ class RecordService {
async
onAudioStop
()
{
async
onAudioStop
()
{
if
(
!
this
.
audioManager
)
return
if
(
!
this
.
audioManager
)
return
if
(
this
.
audioManager
.
isRecording
)
{
if
(
this
.
audioManager
.
isRecording
)
{
uni
.
$logger
.
local
.
info
(
`【接待录音】录音分段结束,自动续录 counter=
${
this
.
audioManager
.
counter
}
, recordId=
${
this
.
record
?.
currentRecord
?.
id
||
''
}
`)
uni.$logger.local.info('【录音服务RecordService】 == 接待中,再次开启录音! ')
uni.$logger.local.info('【录音服务RecordService】 == 接待中,再次开启录音! ')
this.audioManager.start()
this.audioManager.start()
} else {
} else {
uni.$logger.local.info(`
【接待录音】录音停止,不再续录
recordId
=
$
{
this
.
record
?.
currentRecord
?.
id
||
''
}
`)
uni.$logger.local.info('【录音服务RecordService】 == 断开录音! ')
uni.$logger.local.info('【录音服务RecordService】 == 断开录音! ')
}
}
}
}
...
@@ -248,6 +255,9 @@ class RecordService {
...
@@ -248,6 +255,9 @@ class RecordService {
uni
.
$logger
.
local
.
warn
(
'【录音服务RecordService】 == 未开始接待,不能结束接待! '
)
uni
.
$logger
.
local
.
warn
(
'【录音服务RecordService】 == 未开始接待,不能结束接待! '
)
return
return
}
}
const
record
=
this
.
record
?.
currentRecord
const
fileCount
=
record
?.
recordUrlList
?.
length
||
0
uni
.
$logger
.
local
.
info
(
`【接待录音】结束接待: recordId=
${
record
?.
id
||
''
},
fileCount
=
$
{
fileCount
},
isNotSave
=
$
{
isNotSave
}
`)
uni.$logger.local.info('【录音服务RecordService】 == 结束接待! ')
uni.$logger.local.info('【录音服务RecordService】 == 结束接待! ')
this.stop()
this.stop()
await this._teardownAiClientForReception().catch(() => {})
await this._teardownAiClientForReception().catch(() => {})
...
@@ -260,6 +270,9 @@ class RecordService {
...
@@ -260,6 +270,9 @@ class RecordService {
}
}
async
saveAndClearRecord
(
isNotSave
=
false
)
{
async
saveAndClearRecord
(
isNotSave
=
false
)
{
const
record
=
this
.
record
?.
currentRecord
const
files
=
(
record
?.
recordUrlList
||
[]).
map
(
i
=>
i
.
file
).
join
(
', '
)
uni
.
$logger
.
local
.
info
(
`【接待录音】保存记录: recordId=
${
record
?.
id
||
''
},
files
=
[
$
{
files
}],
isNotSave
=
$
{
isNotSave
}
`)
if (isNotSave) {
if (isNotSave) {
//如果不需要保存记录
//如果不需要保存记录
uni.$logger.local.info('【录音服务RecordService】 == 不保存记录! ')
uni.$logger.local.info('【录音服务RecordService】 == 不保存记录! ')
...
@@ -276,6 +289,7 @@ class RecordService {
...
@@ -276,6 +289,7 @@ class RecordService {
this.stopAudioRecord()
this.stopAudioRecord()
}
}
onTimeOut() {
onTimeOut() {
uni.$logger.local.warn(`
【接待录音】闲置超时自动停止
:
recordId
=
$
{
this
.
record
?.
currentRecord
?.
id
||
''
}
`)
store.commit('audio/setReceptionStatus', 0)
store.commit('audio/setReceptionStatus', 0)
this.record.withError()
this.record.withError()
this.stopAudioRecord()
this.stopAudioRecord()
...
@@ -295,7 +309,7 @@ class RecordService {
...
@@ -295,7 +309,7 @@ class RecordService {
const useWs = !!wsBase
const useWs = !!wsBase
const transport = useWs ? TransportType.WEBSOCKET : TransportType.HTTP
const transport = useWs ? TransportType.WEBSOCKET : TransportType.HTTP
// HTTP 服务端固定为 /health(可在 AiAssistantBall 内按需覆盖)
// HTTP 服务端固定为 /health(可在 AiAssistantBall 内按需覆盖)
const
httpBaseUrl
=
'http
://192.168.3.84:8616
'
const httpBaseUrl = 'http
s://lightmodification.test.glsx.com.cn
'
const client = new NativeChannelClient(
const client = new NativeChannelClient(
useWs ? { transport } : { transport, baseUrl: httpBaseUrl }
useWs ? { transport } : { transport, baseUrl: httpBaseUrl }
...
...
utils/recordManager/TempRecord.js
View file @
e8ff93d
...
@@ -76,6 +76,7 @@ class TempRecord {
...
@@ -76,6 +76,7 @@ class TempRecord {
try
{
try
{
if
(
!
record
)
throw
new
Error
(
'记录对象为空'
)
if
(
!
record
)
throw
new
Error
(
'记录对象为空'
)
uni
.
$logger
.
local
.
info
(
'〖接待记录Record〗 == 开始持久化记录 =='
+
JSON
.
stringify
(
record
))
uni
.
$logger
.
local
.
info
(
'〖接待记录Record〗 == 开始持久化记录 =='
+
JSON
.
stringify
(
record
))
uni
.
$logger
.
local
.
info
(
`【接待录音】转正入库: recordId=
${
record
.
id
}
, fileCount=
${
record
.
recordUrlList
?.
length
||
0
}
`)
uni.$logger.local.info('〖接待记录Record〗 == 更新文件,保存记录!')
uni.$logger.local.info('〖接待记录Record〗 == 更新文件,保存记录!')
// 直接更新原记录,不再插入新记录
// 直接更新原记录,不再插入新记录
await this.dbRecord.updateRecord(toUpdateData, { id: record.id })
await this.dbRecord.updateRecord(toUpdateData, { id: record.id })
...
@@ -83,6 +84,7 @@ class TempRecord {
...
@@ -83,6 +84,7 @@ class TempRecord {
await this.clearLocalRecord(record, false) // 传入 false 表示不删除数据库记录
await this.clearLocalRecord(record, false) // 传入 false 表示不删除数据库记录
this.triggerRecordNumChanged()
this.triggerRecordNumChanged()
// 触发轮询开始事件,通知上传管理重新开始轮询
// 触发轮询开始事件,通知上传管理重新开始轮询
uni.$logger.local.info(`
【接待录音】触发上传轮询
:
recordId
=
$
{
record
.
id
}
`
)
RecordSaveService
.
startPolling
()
RecordSaveService
.
startPolling
()
}
catch
(
error
)
{
}
catch
(
error
)
{
uni
.
$logger
.
local
.
info
(
'〖接待记录Record〗 == 保存记录异常'
+
error
.
message
)
uni
.
$logger
.
local
.
info
(
'〖接待记录Record〗 == 保存记录异常'
+
error
.
message
)
...
@@ -96,6 +98,9 @@ class TempRecord {
...
@@ -96,6 +98,9 @@ class TempRecord {
}
}
async
save
(
record
=
this
.
record
)
{
async
save
(
record
=
this
.
record
)
{
const
fileCount
=
record
?.
recordUrlList
?.
length
||
0
const
files
=
(
record
?.
recordUrlList
||
[]).
map
(
i
=>
i
.
file
).
join
(
', '
)
uni
.
$logger
.
local
.
info
(
`【接待录音】TempRecord.save: recordId=
${
record
?.
id
},
fileCount
=
$
{
fileCount
},
files
=
[
$
{
files
}]
`)
await this.beforeSave(record)
await this.beforeSave(record)
return this.__save(record, {})
return this.__save(record, {})
}
}
...
...
utils/recordManager/helpler.js
View file @
e8ff93d
...
@@ -24,8 +24,13 @@ async function getLatestAudioFilePath(excludePath = '') {
...
@@ -24,8 +24,13 @@ async function getLatestAudioFilePath(excludePath = '') {
}
}
const
pathName
=
await
__getAudioPathName
(
excludeName
)
const
pathName
=
await
__getAudioPathName
(
excludeName
)
if
(
!
pathName
)
return
''
if
(
!
pathName
)
{
return
await
__getAudioPath
(
pathName
)
uni
.
$logger
.
local
.
warn
(
`【接待录音】未找到录音文件, excludeName=
${
excludeName
}
`
)
return
''
}
const
fullPath
=
await
__getAudioPath
(
pathName
)
uni
.
$logger
.
local
.
info
(
`【接待录音】找到最新录音:
${
fullPath
}
`
)
return
fullPath
}
catch
(
error
)
{
}
catch
(
error
)
{
uni
.
$logger
.
local
.
warn
(
'〖接待记录Record〗 == 获取最新录音路径异常: '
+
error
.
message
)
uni
.
$logger
.
local
.
warn
(
'〖接待记录Record〗 == 获取最新录音路径异常: '
+
error
.
message
)
return
''
return
''
...
...
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