|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+<template>
|
|
|
2
|
+ <div class="h-full bg-white p-6 flex flex-col">
|
|
|
3
|
+ <!-- 头部 -->
|
|
|
4
|
+ <div class="flex justify-between items-center mb-8">
|
|
|
5
|
+ <h2 class="text-xl font-medium">通话录音</h2>
|
|
|
6
|
+ <el-icon class="cursor-pointer text-gray-400 hover:text-gray-600" @click="drawerVisible = false">
|
|
|
7
|
+ <Close />
|
|
|
8
|
+ </el-icon>
|
|
|
9
|
+ </div>
|
|
|
10
|
+ <!-- 音频播放器 -->
|
|
|
11
|
+ <div class="bg-gray-50 rounded-lg p-6 mb-6">
|
|
|
12
|
+ <div class="flex justify-center mb-4">
|
|
|
13
|
+ <audio ref="audioPlayer" :src="filePath" @timeupdate="updateTime"></audio>
|
|
|
14
|
+ <el-button class="w-16 h-16 !rounded-full flex items-center justify-center"
|
|
|
15
|
+ :type="isPlaying ? 'danger' : 'primary'" @click="togglePlay">
|
|
|
16
|
+ <el-icon class="text-4xl">
|
|
|
17
|
+ <component :is="isPlaying ? 'VideoPause' : 'VideoPlay'" />
|
|
|
18
|
+ </el-icon>
|
|
|
19
|
+ </el-button>
|
|
|
20
|
+ </div>
|
|
|
21
|
+ <!-- 进度条 -->
|
|
|
22
|
+ <div class="mb-2">
|
|
|
23
|
+ <el-slider v-model="progress" :max="100" @change="handleProgressChange" />
|
|
|
24
|
+ </div>
|
|
|
25
|
+ <!-- 时间显示 -->
|
|
|
26
|
+ <div class="flex justify-between text-sm text-gray-500">
|
|
|
27
|
+ <span>{{ formatTime(currentTime) }}</span>
|
|
|
28
|
+ <span>{{ formatTime(duration) }}</span>
|
|
|
29
|
+ </div>
|
|
|
30
|
+ </div>
|
|
|
31
|
+ <!-- 操作按钮 -->
|
|
|
32
|
+ <div class="mb-6">
|
|
|
33
|
+ <el-button type="primary" class="w-full !rounded-button whitespace-nowrap" @click="handleDownload">
|
|
|
34
|
+ <el-icon class="mr-2">
|
|
|
35
|
+ <Download />
|
|
|
36
|
+ </el-icon>
|
|
|
37
|
+ 下载录音
|
|
|
38
|
+ </el-button>
|
|
|
39
|
+ </div>
|
|
|
40
|
+ <!-- 转写内容 -->
|
|
|
41
|
+ <div class="bg-white rounded-lg p-4 flex flex-col flex-grow overflow-hidden mb-6"
|
|
|
42
|
+ v-if="transcriptionMessages.length">
|
|
|
43
|
+ <h3 class="text-lg font-medium mb-4">语音转写内容</h3>
|
|
|
44
|
+ <div class="text-gray-600 leading-relaxed overflow-y-auto flex-grow space-y-2">
|
|
|
45
|
+ <div v-for="(message, index) in transcriptionMessages" :key="index" @click="jumpToTime(message.startTime)"
|
|
|
46
|
+ :class="[
|
|
|
47
|
+ 'p-3 transition-colors rounded-lg cursor-pointer group',
|
|
|
48
|
+ message.direction === 1 ? 'bg-gradient-to-r from-gray-100 to-gray-200 hover:from-gray-200 hover:to-gray-300' : 'bg-gradient-to-r from-blue-50 to-blue-100 hover:from-blue-100 hover:to-blue-200'
|
|
|
49
|
+ ]">
|
|
|
50
|
+ <div class="flex justify-between items-center mb-2">
|
|
|
51
|
+ <div class="flex items-center gap-2">
|
|
|
52
|
+ <div class="text-xs text-gray-400">{{ message.timestamp }}</div>
|
|
|
53
|
+ <div :class="[
|
|
|
54
|
+ 'px-2 py-1 rounded-full text-xs font-medium whitespace-nowrap',
|
|
|
55
|
+ message.direction === 1 ? 'bg-gray-200 text-gray-700 border border-gray-300' : 'bg-blue-100 text-blue-600 border border-blue-200'
|
|
|
56
|
+ ]">
|
|
|
57
|
+ {{ message.direction === 1 ? '客服' : '客户' }}
|
|
|
58
|
+ </div>
|
|
|
59
|
+ </div>
|
|
|
60
|
+ <el-button class="!rounded-button opacity-0 group-hover:opacity-100 transition-opacity" size="small"
|
|
|
61
|
+ type="text" @click.stop="playSegment(message.startTime, message.endTime)">
|
|
|
62
|
+ <el-icon class="text-lg">
|
|
|
63
|
+ <VideoPlay />
|
|
|
64
|
+ </el-icon>
|
|
|
65
|
+ </el-button>
|
|
|
66
|
+ </div>
|
|
|
67
|
+ <div class="text-gray-700">{{ message.page_content }}</div>
|
|
|
68
|
+ <!-- <div class="text-xs text-gray-400 mt-1">置信度: {{ message.confidence }}%</div> -->
|
|
|
69
|
+ </div>
|
|
|
70
|
+ </div>
|
|
|
71
|
+ </div>
|
|
|
72
|
+ <!-- 关键词模块 -->
|
|
|
73
|
+ <div class="mb-6" v-if="keywords.length">
|
|
|
74
|
+ <h2 class="text-lg font-semibold mb-4">关键词</h2>
|
|
|
75
|
+ <div class="flex flex-wrap gap-3">
|
|
|
76
|
+ <div v-for="(keyword, index) in keywords" :key="index"
|
|
|
77
|
+ class="relative inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-blue-100 text-blue-800">
|
|
|
78
|
+ {{ keyword.text }}
|
|
|
79
|
+ <span
|
|
|
80
|
+ class="absolute -top-2 -right-2 flex items-center justify-center w-5 h-5 text-xs font-bold text-white bg-red-500 rounded-full">{{
|
|
|
81
|
+ keyword.count }}</span>
|
|
|
82
|
+ </div>
|
|
|
83
|
+ </div>
|
|
|
84
|
+ </div>
|
|
|
85
|
+ </div>
|
|
|
86
|
+</template>
|
|
|
87
|
+
|
|
|
88
|
+<script lang="ts" setup>
|
|
|
89
|
+import { ref, reactive, watch, onMounted } from 'vue';
|
|
|
90
|
+import { ElMessage } from 'element-plus';
|
|
|
91
|
+import { Close, VideoPlay, VideoPause, Download } from '@element-plus/icons-vue';
|
|
|
92
|
+import { flatten } from 'lodash';
|
|
|
93
|
+
|
|
|
94
|
+import { getPageListData } from '@/api/main/system/system';
|
|
|
95
|
+import { stripHtmlByRegex, formatMilliseconds } from '@/utils/tools';
|
|
|
96
|
+
|
|
|
97
|
+const drawerVisible = ref(false);
|
|
|
98
|
+const deleteDialogVisible = ref(false);
|
|
|
99
|
+const isPlaying = ref(false);
|
|
|
100
|
+const callId = ref(0);
|
|
|
101
|
+const filePath = ref('');
|
|
|
102
|
+const audioPlayer = ref(null);
|
|
|
103
|
+const props = defineProps({
|
|
|
104
|
+ callId: {
|
|
|
105
|
+ type: Number,
|
|
|
106
|
+ },
|
|
|
107
|
+ filePath: {
|
|
|
108
|
+ type: String,
|
|
|
109
|
+ },
|
|
|
110
|
+});
|
|
|
111
|
+watch(props, (newValue, oldValue) => {
|
|
|
112
|
+ if (newValue) {
|
|
|
113
|
+ callId.value = props.callId;
|
|
|
114
|
+ filePath.value = props.filePath;
|
|
|
115
|
+ }
|
|
|
116
|
+});
|
|
|
117
|
+
|
|
|
118
|
+const progress = ref(0);
|
|
|
119
|
+const currentTime = ref(0);
|
|
|
120
|
+const duration = ref(180); // 示例时长3分钟
|
|
|
121
|
+const transcriptionMessages: any = ref([]);
|
|
|
122
|
+const formatTime = (seconds: number): string => {
|
|
|
123
|
+ const minutes = Math.floor(seconds / 60);
|
|
|
124
|
+ const remainingSeconds = Math.floor(seconds % 60);
|
|
|
125
|
+ return `${minutes.toString().padStart(2, '0')}:${remainingSeconds.toString().padStart(2, '0')}`;
|
|
|
126
|
+};
|
|
|
127
|
+const togglePlay = () => {
|
|
|
128
|
+ isPlaying.value = !isPlaying.value;
|
|
|
129
|
+ if (isPlaying.value) {
|
|
|
130
|
+ pause();
|
|
|
131
|
+ // 模拟播放进度
|
|
|
132
|
+ const timer = setInterval(() => {
|
|
|
133
|
+ if (progress.value >= 100) {
|
|
|
134
|
+ clearInterval(timer);
|
|
|
135
|
+ isPlaying.value = false;
|
|
|
136
|
+ progress.value = 0;
|
|
|
137
|
+ currentTime.value = 0;
|
|
|
138
|
+ return;
|
|
|
139
|
+ }
|
|
|
140
|
+ progress.value += 1;
|
|
|
141
|
+ currentTime.value = (progress.value / 100) * duration.value;
|
|
|
142
|
+ }, 1000);
|
|
|
143
|
+ }
|
|
|
144
|
+};
|
|
|
145
|
+const handleProgressChange = (value: number) => {
|
|
|
146
|
+ currentTime.value = (value / 100) * duration.value;
|
|
|
147
|
+};
|
|
|
148
|
+const jumpToTime = (time: number) => {
|
|
|
149
|
+ progress.value = (time / duration.value) * 100;
|
|
|
150
|
+ currentTime.value = time;
|
|
|
151
|
+};
|
|
|
152
|
+
|
|
|
153
|
+const handleDownload = () => {
|
|
|
154
|
+ ElMessage.success('录音文件下载中...');
|
|
|
155
|
+};
|
|
|
156
|
+const handleDelete = () => {
|
|
|
157
|
+ deleteDialogVisible.value = true;
|
|
|
158
|
+};
|
|
|
159
|
+const confirmDelete = () => {
|
|
|
160
|
+ deleteDialogVisible.value = false;
|
|
|
161
|
+ drawerVisible.value = false;
|
|
|
162
|
+ ElMessage.success('录音已删除');
|
|
|
163
|
+};
|
|
|
164
|
+const openDrawer = () => {
|
|
|
165
|
+ drawerVisible.value = true;
|
|
|
166
|
+ progress.value = 0;
|
|
|
167
|
+ currentTime.value = 0;
|
|
|
168
|
+ isPlaying.value = false;
|
|
|
169
|
+};
|
|
|
170
|
+let keywords = reactive([]);
|
|
|
171
|
+
|
|
|
172
|
+const getDetail = () => {
|
|
|
173
|
+ callId.value = 526;
|
|
|
174
|
+ getPageListData(`/call/translate/${callId.value}`).then(({ data }) => {
|
|
|
175
|
+ console.log(data, 'res')
|
|
|
176
|
+ if (data.translate) {
|
|
|
177
|
+ const translate = JSON.parse(data.translate);
|
|
|
178
|
+ transcriptionMessages.value = translate.map((msg: any) => {
|
|
|
179
|
+
|
|
|
180
|
+ const msgInfo: any = {
|
|
|
181
|
+ direction: msg.Number.toString().length > 4 ? 2 : 1,
|
|
|
182
|
+ page_content: msg.Speech || '',
|
|
|
183
|
+ startTime: 0,
|
|
|
184
|
+ endTime: 0,
|
|
|
185
|
+ timestamp: '',
|
|
|
186
|
+ };
|
|
|
187
|
+ // console.log(msg.Time, 'msgInfo');
|
|
|
188
|
+ if (msg.Time) {
|
|
|
189
|
+ const times = JSON.parse(msg.Time);
|
|
|
190
|
+ if (times?.length) {
|
|
|
191
|
+ const timeArray = flatten(times);
|
|
|
192
|
+ const time = timeArray?.[0];
|
|
|
193
|
+ if (time) {
|
|
|
194
|
+ msgInfo.timestamp = formatMilliseconds(time);
|
|
|
195
|
+ msgInfo.startTime = timeArray[0];
|
|
|
196
|
+ msgInfo.endTime = timeArray[timeArray.length - 1];
|
|
|
197
|
+ }
|
|
|
198
|
+ }
|
|
|
199
|
+ }
|
|
|
200
|
+
|
|
|
201
|
+ return msgInfo;
|
|
|
202
|
+
|
|
|
203
|
+ })
|
|
|
204
|
+
|
|
|
205
|
+ }
|
|
|
206
|
+
|
|
|
207
|
+ if (data.translateJson) {
|
|
|
208
|
+ keywords = JSON.parse(data.translateJson);
|
|
|
209
|
+
|
|
|
210
|
+ }
|
|
|
211
|
+ })
|
|
|
212
|
+}
|
|
|
213
|
+
|
|
|
214
|
+const startTime = ref(0);
|
|
|
215
|
+const endTime = ref(0);
|
|
|
216
|
+// const duration = ref(0);
|
|
|
217
|
+// const isPlaying = ref(false);
|
|
|
218
|
+// const currentTime = ref(0);
|
|
|
219
|
+
|
|
|
220
|
+const playSegment = (sTime: number, eTime: number) => {
|
|
|
221
|
+ progress.value = (sTime / duration.value) * 100;
|
|
|
222
|
+ currentTime.value = sTime;
|
|
|
223
|
+ endTime.value = eTime;
|
|
|
224
|
+ // isPlaying.value = true;
|
|
|
225
|
+ playVideoSegment();
|
|
|
226
|
+};
|
|
|
227
|
+
|
|
|
228
|
+// 播放指定区间
|
|
|
229
|
+const playVideoSegment = () => {
|
|
|
230
|
+ if (!audioPlayer.src) return;
|
|
|
231
|
+
|
|
|
232
|
+ audioPlayer.currentTime = startTime.value;
|
|
|
233
|
+ audioPlayer.play();
|
|
|
234
|
+ isPlaying.value = true;
|
|
|
235
|
+
|
|
|
236
|
+ // 模拟播放到指定片段结束
|
|
|
237
|
+ const timer = setInterval(() => {
|
|
|
238
|
+ if (currentTime.value >= endTime.value || !isPlaying.value) {
|
|
|
239
|
+ clearInterval(timer);
|
|
|
240
|
+ isPlaying.value = false;
|
|
|
241
|
+ return;
|
|
|
242
|
+ }
|
|
|
243
|
+ progress.value = (currentTime.value / duration.value) * 100;
|
|
|
244
|
+ currentTime.value += 1;
|
|
|
245
|
+ }, 1000);
|
|
|
246
|
+
|
|
|
247
|
+ // 设置区间结束监听
|
|
|
248
|
+ const checkEnd = () => {
|
|
|
249
|
+ if (audioPlayer.currentTime >= endTime.value) {
|
|
|
250
|
+ pause();
|
|
|
251
|
+ audioPlayer.currentTime = startTime.value; // 回到起点
|
|
|
252
|
+ } else if (isPlaying.value) {
|
|
|
253
|
+ requestAnimationFrame(checkEnd);
|
|
|
254
|
+ }
|
|
|
255
|
+ };
|
|
|
256
|
+ requestAnimationFrame(checkEnd);
|
|
|
257
|
+};
|
|
|
258
|
+
|
|
|
259
|
+// 暂停播放
|
|
|
260
|
+const pause = () => {
|
|
|
261
|
+ console.log(audioPlayer, 'audioPlayer');
|
|
|
262
|
+ audioPlayer.play();
|
|
|
263
|
+ isPlaying.value = false;
|
|
|
264
|
+}
|
|
|
265
|
+
|
|
|
266
|
+// 停止并重置
|
|
|
267
|
+const stop = () => {
|
|
|
268
|
+ pause();
|
|
|
269
|
+ audioPlayer.currentTime = startTime.value;
|
|
|
270
|
+ currentTime.value = startTime.value;
|
|
|
271
|
+}
|
|
|
272
|
+
|
|
|
273
|
+// 更新当前时间
|
|
|
274
|
+const updateTime = () => {
|
|
|
275
|
+ currentTime.value = audioPlayer.currentTime;
|
|
|
276
|
+}
|
|
|
277
|
+
|
|
|
278
|
+const loadRemoteAudio = async () => {
|
|
|
279
|
+ if (!filePath.value) return
|
|
|
280
|
+
|
|
|
281
|
+ try {
|
|
|
282
|
+
|
|
|
283
|
+
|
|
|
284
|
+ // 创建音频对象
|
|
|
285
|
+ const audio = audioPlayer.value
|
|
|
286
|
+ audio.src = filePath.value
|
|
|
287
|
+
|
|
|
288
|
+ // 等待元数据加载
|
|
|
289
|
+ await new Promise((resolve, reject) => {
|
|
|
290
|
+ audio.onloadedmetadata = () => {
|
|
|
291
|
+ duration.value = audio.duration
|
|
|
292
|
+ endTime.value = audio.duration
|
|
|
293
|
+ resolve(1)
|
|
|
294
|
+ }
|
|
|
295
|
+
|
|
|
296
|
+ audio.onerror = (e) => {
|
|
|
297
|
+ reject(new Error('音频加载失败'))
|
|
|
298
|
+ }
|
|
|
299
|
+
|
|
|
300
|
+ // 设置超时处理
|
|
|
301
|
+ setTimeout(() => {
|
|
|
302
|
+ reject(new Error('音频加载超时'))
|
|
|
303
|
+ }, 10000)
|
|
|
304
|
+ })
|
|
|
305
|
+ } catch (err) {
|
|
|
306
|
+ console.log(err)
|
|
|
307
|
+ } finally {
|
|
|
308
|
+ }
|
|
|
309
|
+}
|
|
|
310
|
+
|
|
|
311
|
+onMounted(() => {
|
|
|
312
|
+ callId.value = props.callId;
|
|
|
313
|
+ filePath.value = 'http://1.194.161.64:9000/files/luyin/20250228/1011/8a5d1910-a6cf-4674-acb9-61f29f00cb05.wav';
|
|
|
314
|
+ if (filePath.value) {
|
|
|
315
|
+ // audioPlayer.src = filePath.value;
|
|
|
316
|
+ // audioPlayer.onloadedmetadata = () => {
|
|
|
317
|
+ // duration.value = audioPlayer.duration;
|
|
|
318
|
+ // endTime.value = audioPlayer.duration;
|
|
|
319
|
+ // };
|
|
|
320
|
+ loadRemoteAudio();
|
|
|
321
|
+ }
|
|
|
322
|
+ getDetail();
|
|
|
323
|
+});
|
|
|
324
|
+</script>
|
|
|
325
|
+<style scoped>
|
|
|
326
|
+.el-drawer__body {
|
|
|
327
|
+ padding: 0;
|
|
|
328
|
+ overflow: hidden;
|
|
|
329
|
+}
|
|
|
330
|
+
|
|
|
331
|
+/* 隐藏滚动条但保留滚动功能 */
|
|
|
332
|
+.overflow-y-auto::-webkit-scrollbar {
|
|
|
333
|
+ display: none;
|
|
|
334
|
+}
|
|
|
335
|
+
|
|
|
336
|
+.overflow-y-auto {
|
|
|
337
|
+ -ms-overflow-style: none;
|
|
|
338
|
+ scrollbar-width: none;
|
|
|
339
|
+}
|
|
|
340
|
+</style>
|