diff --git a/public/dicts/en/article/common/NCE_2.json b/public/dicts/en/article/common/NCE_2.json
index 84383c2f..4830d25f 100644
--- a/public/dicts/en/article/common/NCE_2.json
+++ b/public/dicts/en/article/common/NCE_2.json
@@ -8,17 +8,21 @@
"newWords": [],
"textCustomTranslateIsFormat": true,
"useTranslateType": "custom",
- "id": "HmlGhw"
+ "id": "HmlGhw",
+ "audioSrc": "/public/sound/article/nce2-1/1.mp3",
+ "lrcPosition": [[14.6,19.15],[19.15,22.03],[22.03,24.59],[24.59,27.26],[27.26,31.65],[31.65,34.43],[34.43,36.98],[36.98,40.36],[40.7,42.47],[40.36,46.59],[46.59,50.65],[50.65,54.57],[55.03,56.84],[57.17,63],[62.98,68.85],[68.85,-1]]
},
{
"title": "Breakfast or lunch?",
"titleTranslate": "早餐还是午餐?",
- "text": "It was Sunday. I never get up early on Sundays. I sometimes stay in bed until lunchtime. Last Sunday I got up very late. I looked out of the window. It was dark outside. 'What a day!' I thought. 'It's raining again.' Just then, the telephone rang. It was my aunt Lucy. 'I've just arrived by train,' she said. 'I'm coming to see you.'\n 'But I'm still having breakfast,' I said.\n 'What are you doing?' she asked.\n 'I'm having breakfast,' I repeated.\n 'Dear me,' she said. 'Do you always get up so late? It's one o'clock!'",
- "textCustomTranslate": "那是个星期天,\n而在星期天我是从来不早起的,\n有时我要一直躺到吃午饭的时候。\n上个星期天,我起得很晚。\n我望望窗外,外面一片昏暗。\n“鬼天气!”\n我想,“又下雨了。”\n正在这时,电话铃响了。\n是我姑母露西打来的。\n“我刚下火车,”她说,\n“我这就来看你。”\n\n“但我还在吃早饭,”我说。\n\n“你在干什么?”她问道。\n\n“我正在吃早饭,”我又说了一遍。\n\n“天啊,”她说,\n“你总是起得这么晚吗?",
+ "text": "It was Sunday. I never get up early on Sundays. I sometimes stay in bed until lunchtime. Last Sunday I got up very late. I looked out of the window. It was dark outside. 'What a day!' I thought. 'It's raining again.' Just then, the telephone rang. It was my aunt Lucy. 'I've just arrived by train,' she said. 'I'm coming to see you.'\n\n 'But I'm still having breakfast,' I said.\n\n 'What are you doing?' she asked.\n\n 'I'm having breakfast,' I repeated.\n\n 'Dear me,' she said. 'Do you always get up so late? It's one o'clock!'",
+ "textCustomTranslate": "那是个星期天,\n而在星期天我是从来不早起的,\n有时我要一直躺到吃午饭的时候。\n上个星期天,我起得很晚。\n我望望窗外,\n外面一片昏暗。\n“鬼天气!”我想,\n“又下雨了。”正在这时,电话铃响了。\n是我姑母露西打来的。\n“我刚下火车,”她说,\n“我这就来看你。”\n\n“但我还在吃早饭,”我说。\n\n“你在干什么?”她问道。\n\n“我正在吃早饭,”我又说了一遍。\n\n“天啊,”她说,\n“你总是起得这么晚吗?现在已经1点钟了!",
"textNetworkTranslate": "",
"textCustomTranslateIsFormat": true,
"useTranslateType": "custom",
"newWords": [],
+ "audioSrc": "/public/sound/article/nce2-1/2.mp3",
+ "lrcPosition": [],
"id": "1ao0Qx"
},
{
diff --git a/public/sound/article/nce2-1/2.lrc b/public/sound/article/nce2-1/2.lrc
new file mode 100644
index 00000000..6c54e75f
--- /dev/null
+++ b/public/sound/article/nce2-1/2.lrc
@@ -0,0 +1,18 @@
+
+[ti:¸Ӣڶ]
+[by:http://www.TingClass.com]
+[00:02.77]Lesson 2
+[00:04.08] Breakfast or lunch?
+[00:06.06]First listen and then answer the question:
+[00:10.85]Why was the writer's aunt surprised?
+[00:16.35]It was Sunday.I never get up early on Sundays.
+[00:21.54]I sometimes stay in bed until lunchtime.
+[00:27.48]Last Sunday I got up very late.
+[00:31.76]I looked out of the window. It was dark outside.
+[00:37.01]'What a day!'I thought. 'It's raining again.'
+[00:43.20]Just then,the telephone rang.It was my aunt Lucy.
+[00:49.33]'I've just arrived by train,' she said.'I'm coming to see you.'
+[00:56.43]'But I'm still having breakfast,'I said. 'What are you doing? she asked.
+[01:04.20]'I'm having breakfast,'I repeated.
+[01:08.00]'Dear me,'she said.
+[01:10.88] 'Do you always get up so late? It's one o'clock!'
diff --git a/public/sound/article/nce2-1/2.mp3 b/public/sound/article/nce2-1/2.mp3
new file mode 100644
index 00000000..6e730358
Binary files /dev/null and b/public/sound/article/nce2-1/2.mp3 differ
diff --git a/src/hooks/article.ts b/src/hooks/article.ts
index c8b195b0..93ff1bde 100644
--- a/src/hooks/article.ts
+++ b/src/hooks/article.ts
@@ -50,6 +50,7 @@ export function splitEnArticle(text: string): { sections: Sentence[][], newText:
let sentenceNlpList = []
// console.log('ss', sentenceNlpList)
doc.json().map(item => {
+
//如果整句大于15个单词以上,检测是否有 逗号子句
if (item.terms.length > 15) {
//正则匹配“逗号加and|but|so|because"
@@ -71,13 +72,14 @@ export function splitEnArticle(text: string): { sections: Sentence[][], newText:
})
sentenceNlpList.map(item => {
- let sentence: Sentence = {
+ let sentence: Sentence = cloneDeep({
//他没有空格,导致修改一行一行的数据时,汇总时全没有空格了,库无法正常断句
text: item.text + ' ',
// text: '',
translate: '',
words: [],
- }
+ audioPosition: [],
+ })
section.push(sentence)
const checkQuote = (pre: string, index?: number) => {
@@ -126,6 +128,7 @@ export function splitEnArticle(text: string): { sections: Sentence[][], newText:
lastSentence.words = lastSentence.words.concat(sentence.words)
lastSentence.words.push(word3)
sentence.words = []
+ //这里还不能直接删除sentence,因为后面还有一个 sentence.words = sentence.words.filter(v => v.word !== 'placeholder') 的判断
// section.pop()
}
}
@@ -218,6 +221,10 @@ export function splitEnArticle(text: string): { sections: Sentence[][], newText:
//去除空格占位符
sentence.words = sentence.words.filter(v => v.word !== 'placeholder')
+ //如果是空的,直接去掉
+ if (!sentence.words.length) {
+ section.pop()
+ }
})
// console.log(sentenceNlpList)
diff --git a/src/hooks/translate.ts b/src/hooks/translate.ts
index 6af3d208..46d82bb0 100644
--- a/src/hooks/translate.ts
+++ b/src/hooks/translate.ts
@@ -197,4 +197,11 @@ export function renewSectionTexts(article: Article) {
let {newText, sections} = splitEnArticle(article.text)
article.text = newText
article.sections = sections
+ if (article.lrcPosition.length) {
+ article.sections.map((v, i) => {
+ v.map((w, j) => {
+ w.audioPosition = article.lrcPosition[(i * (article.sections[i - 1]||[]).length) + j]
+ })
+ })
+ }
}
diff --git a/src/pages/pc/article/ArticleFooter.vue b/src/pages/pc/article/ArticleFooter.vue
deleted file mode 100644
index 4ecb119b..00000000
--- a/src/pages/pc/article/ArticleFooter.vue
+++ /dev/null
@@ -1,222 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/pages/pc/article/LearnArticle.vue b/src/pages/pc/article/LearnArticle.vue
index 43922751..38e1bc38 100644
--- a/src/pages/pc/article/LearnArticle.vue
+++ b/src/pages/pc/article/LearnArticle.vue
@@ -137,27 +137,10 @@ useStartKeyboardEventListener()
-
-
-
-
+
\ No newline at end of file
diff --git a/src/pages/pc/components/article/EditArticle.vue b/src/pages/pc/components/article/EditArticle.vue
index 50cd2396..b9258a1b 100644
--- a/src/pages/pc/components/article/EditArticle.vue
+++ b/src/pages/pc/components/article/EditArticle.vue
@@ -14,7 +14,7 @@ import {
import {MessageBox} from "@/utils/MessageBox.tsx";
import {getSplitTranslateText} from "@/hooks/article.ts";
-import {cloneDeep} from "lodash-es";
+import {cloneDeep, last} from "lodash-es";
import {watch, ref} from "vue";
import Empty from "@/components/Empty.vue";
import {UploadProps, UploadUserFile} from "element-plus";
@@ -72,7 +72,7 @@ watch(() => props.article, val => {
}
}
renewSections()
- // console.log('ar', article)
+ console.log('ar', editArticle)
}, {immediate: true})
watch(() => editArticle.text, (s) => {
@@ -238,86 +238,63 @@ function save(option: 'save' | 'saveAndNext') {
//不知道为什么直接用editArticle,取到是空的默认值
defineExpose({save, getEditArticle: () => cloneDeep(editArticle)})
-const fileList = ref([])
-
-const handleExceed: UploadProps['onExceed'] = (files, uploadFiles) => {
- ElMessage.warning(
- `The limit is 3, you selected ${files.length} files this time, add up to ${
- files.length + uploadFiles.length
- } totally`
- )
-}
const handleChange: UploadProps['onChange'] = (uploadFile, uploadFiles) => {
- console.log(1)
- fileList.value.push({
- name: uploadFile.name,
- url: uploadFile.url,
- })
-}
-
-function test() {
- let lrc = `[00:00.00]Lesson 1 A Private Conversation
-[00:04.35]First listen and then answer the question.
-[00:09.26]Why did the writer complain to the people behind him?
-[00:14.60]Last week I went to the theatre.
-[00:19.15]I had a very good seat.
-[00:22.03]The play was very interesting.
-[00:24.59]I did not enjoy it.
-[00:27.26]A young man and a young woman were sitting behind me.
-[00:31.65]They were talking loudly.
-[00:34.43]I got very angry.
-[00:36.98]I could not hear the actors.
-[00:40.36]I turned round.I looked at the man and the woman angrily.
-[00:46.59]They did not pay any attention.
-[00:50.65]In the end,I could not bear it.
-[00:54.57]I turned round again 'I can't hear a word!'I said angrily
-[01:02.98]'It's none of your business,'the young man said rudely.
-[01:08.85]'This is a private conversation!'
-`
- let lrcList = _parseLRC(lrc)
- console.log(lrcList)
- editArticle.sections.map((v, i) => {
- v.map((w, j) => {
- console.log(w)
- for (let k = 0; k < lrcList.length; k++) {
- let s = lrcList[k]
- let d = Comparison.default.cosine.similarity(w.text, s.text)
- d = Comparison.default.levenshtein.similarity(w.text, s.text)
- d = Comparison.default.longestCommonSubsequence.similarity(w.text, s.text)
- // d = Comparison.default.metricLcs.similarity(w.text, s.text)
- console.log(w.text, s.text, d)
- if (d >= 0.8) {
- w.audioPosition = [s.start, s.end ?? -1]
- w.test = s.text
- break
- }
+ console.log(uploadFile)
+ let reader = new FileReader();
+ reader.readAsText(uploadFile.raw, 'UTF-8');
+ reader.onload = function (e) {
+ let lrc: string = e.target.result as string;
+ console.log(lrc)
+ if (lrc.trim()) {
+ let lrcList = _parseLRC(lrc)
+ console.log('lrcList', lrcList)
+ if (lrcList.length) {
+ editArticle.lrcPosition = editArticle.sections.map((v, i) => {
+ return v.map((w, j) => {
+ for (let k = 0; k < lrcList.length; k++) {
+ let s = lrcList[k]
+ let d = Comparison.default.cosine.similarity(w.text, s.text)
+ d = Comparison.default.levenshtein.similarity(w.text, s.text)
+ d = Comparison.default.longestCommonSubsequence.similarity(w.text, s.text)
+ // d = Comparison.default.metricLcs.similarity(w.text, s.text)
+ // console.log(w.text, s.text, d)
+ if (d >= 0.8) {
+ w.audioPosition = [s.start, s.end ?? -1]
+ break
+ }
+ }
+ return w.audioPosition ?? []
+ })
+ }).flat()
}
- })
- })
- console.log(editArticle.sections.flat())
- // console.log(cosine.similarity('Thanos', 'Rival'))
-}
-
-
-function s() {
-
-}
-
-function confirm() {
-
+ }
+ }
}
let currentSentence = $ref({} as any)
+let editSentence = $ref({} as any)
let showEditAudioDialog = $ref(false)
let sentenceAudioRef = $ref()
let audioRef = $ref()
-function handleShowEditAudioDialog(val: Sentence) {
+function handleShowEditAudioDialog(val: Sentence, i: number, j: number) {
showEditAudioDialog = true
currentSentence = val
- if (!currentSentence.audioPosition?.length) {
- currentSentence.audioPosition = [0, 0]
+ editSentence = cloneDeep(val)
+ let pre = null
+ if (j == 0) {
+ if (i != 0) {
+ pre = last(editArticle.sections[i - 1])
+ }
+ } else {
+ pre = editArticle.sections[i][j - 1]
+ }
+ if (!editSentence.audioPosition?.length) {
+ editSentence.audioPosition = [0, 0]
+ if (pre) {
+ editSentence.audioPosition = [pre.audioPosition[1] ?? 0, 0]
+ }
}
}
@@ -325,14 +302,14 @@ function recordStart() {
if (sentenceAudioRef.paused) {
sentenceAudioRef.play()
}
- currentSentence.audioPosition[0] = Number(sentenceAudioRef.currentTime.toFixed(2))
+ editSentence.audioPosition[0] = Number(sentenceAudioRef.currentTime.toFixed(2))
}
function recordEnd() {
if (!sentenceAudioRef.paused) {
sentenceAudioRef.pause()
}
- currentSentence.audioPosition[1] = Number(sentenceAudioRef.currentTime.toFixed(2))
+ editSentence.audioPosition[1] = Number(sentenceAudioRef.currentTime.toFixed(2))
}
let timer = -1
@@ -354,6 +331,12 @@ function playSentenceAudio(sentence: Sentence, ref?: HTMLAudioElement) {
}
}
}
+
+function saveLrcPosition() {
+ // showEditAudioDialog = false
+ currentSentence.audioPosition = cloneDeep(editSentence.audioPosition)
+ editArticle.lrcPosition = editArticle.sections.map((v, i) => v.map((w, j) => (w.audioPosition ?? []))).flat()
+}
@@ -455,21 +438,15 @@ function playSentenceAudio(sentence: Sentence, ref?: HTMLAudioElement) {
正文、译文与结果均可编辑,修改一处,另外两处会自动同步变动
添加音频
- 添加音频LRC
- Click to upload
-
-
- jpg/png files with a size less than 500KB.
-
-
+ 添加音频LRC文件
-
+
@@ -499,10 +476,11 @@ function playSentenceAudio(sentence: Sentence, ref?: HTMLAudioElement) {