index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. <!-- -->
  2. <template>
  3. <div
  4. class="NPC-Book-Article Big-Book-Maxwidth"
  5. v-if="curQue"
  6. v-loading="loading"
  7. >
  8. <div class="Big-Book-img">
  9. <UploadArt
  10. :change-fill-id="changeImage"
  11. :datafile-list="fileCon.img_list"
  12. upload-type="image"
  13. class="article_pdf"
  14. :filleNumber="imageNumber"
  15. />
  16. <ul
  17. class="uploadArt_list"
  18. v-if="curQue.img_list && curQue.img_list.length > 0"
  19. >
  20. <li
  21. v-for="(artItem, artIndex) in curQue.img_list"
  22. :key="'articleImgList' + artIndex"
  23. >
  24. <img :src="artItem.url" style="width: 26px" />
  25. <span class="art_name">{{ artItem.name }}</span>
  26. <p>
  27. 图片放到第<el-input
  28. class="imgNumber"
  29. type="number"
  30. v-model="artItem.imgNumber"
  31. size="mini"
  32. @input="forceUpdate"
  33. ></el-input
  34. >段落的后面
  35. </p>
  36. <img
  37. src="@/assets/adult/del-close.png"
  38. class="del-close"
  39. @click="delImage(artIndex)"
  40. />
  41. </li>
  42. </ul>
  43. </div>
  44. <div class="Big-Book-mp3">
  45. <Upload
  46. type="mp3"
  47. :changeFillId="changeMp3"
  48. :datafileList="fileCon.mp3_list"
  49. :filleNumber="mp3Number"
  50. :uploadType="'mp3'"
  51. />
  52. <!--
  53. :handleMp3Base64="handleChange"
  54. -->
  55. </div>
  56. <div class="adult-book-input-item">
  57. <span class="adult-book-lable">功能配置:</span>
  58. <div class="adult-book-main" v-if="curQue.checkList">
  59. <el-checkbox-group v-model="curQue.checkList">
  60. <el-checkbox :label="1">显示生词功能</el-checkbox>
  61. <el-checkbox :label="2">语音练习模式</el-checkbox>
  62. <el-checkbox :label="3">取词功能</el-checkbox>
  63. </el-checkbox-group>
  64. </div>
  65. </div>
  66. <div class="NPC-Book-article">
  67. <ArticleChs
  68. :curQue="curQue"
  69. :isPara="isPara"
  70. :changeIsPara="changeIsPara"
  71. />
  72. </div>
  73. <template
  74. v-if="
  75. curQue.mp3_list &&
  76. curQue.mp3_list.length > 0 &&
  77. curQue.mp3_list[0].source
  78. "
  79. >
  80. <div class="create_mp3_list">
  81. <span>引擎音频:</span>
  82. <span class="mp3_file_name">{{ curQue.mp3_list[0].name }}</span>
  83. <img
  84. src="../../../../assets/adult/del-close.png"
  85. class="mp3_del"
  86. @click="delMp3"
  87. />
  88. </div>
  89. </template>
  90. <template v-else>
  91. <el-button :loading="CreadMp3loading" size="small" @click="CreadMp3"
  92. >生成音频</el-button
  93. >
  94. </template>
  95. <div class="NPC-Book-Paragraph" v-if="isPara">
  96. <Paragraph :curQue="curQue" :isClause="isClause" :sureSeg="sureSeg" />
  97. </div>
  98. <div class="NPC-Book-model">
  99. <span class="Big-Book-left-text">拼音位置</span>
  100. <el-radio-group v-model="curQue.pyPosition">
  101. <el-radio :label="'top'">字上面</el-radio>
  102. <el-radio :label="'bottom'">字下面</el-radio>
  103. </el-radio-group>
  104. </div>
  105. <!---上传rlc文件-->
  106. <!-- <div class="NPC-Book-Paragraph" v-if="isClause">
  107. <el-button
  108. type="warning"
  109. size="small"
  110. @click="uploadLRC"
  111. v-if="curQue.detail[0].timeList.length == 0"
  112. >上传lrc文件</el-button
  113. >
  114. <div v-else class="lrc-box">
  115. <span>已有字幕时间节点</span>
  116. <el-button type="text" @click="editTimeList">去编辑</el-button>
  117. </div>
  118. </div> -->
  119. <!---分句-->
  120. <div class="NPC-Book-Paragraph" v-if="isClause">
  121. <Clauseresult :curQue="curQue" :segByWord="segByWord" />
  122. </div>
  123. <div class="lrc-box">
  124. <div
  125. v-if="this.curQue.wordTime && this.curQue.wordTime.length > 0"
  126. class="lrc-box"
  127. >
  128. <span>已有字幕时间节点</span>
  129. <el-button type="text" @click="againWordTime">重新生成</el-button>
  130. <el-button @click="compareTime('句子')" size="medium"
  131. >校对句子字幕时间</el-button
  132. >
  133. <el-button @click="compareTime('文字')" size="medium"
  134. >校对文字字幕时间</el-button
  135. >
  136. </div>
  137. <template v-else>
  138. <el-button v-if="!isWordTime" size="medium" @click="createWordTime"
  139. >自动生成字幕节点</el-button
  140. >
  141. <p v-else>字幕节点生成中...请等待</p>
  142. </template>
  143. </div>
  144. <!---分词-->
  145. <div class="NPC-Book-Word" v-if="isByWord">
  146. <Segbyword :curQue="curQue" :paraIndex="paraIndex" :segList="segList" />
  147. </div>
  148. <el-dialog title="段落分句字幕打点" :visible.sync="cTVisible" width="30%">
  149. <Createtimelist ref="createtimelist" :curQue="curQue" />
  150. <span slot="footer" class="dialog-footer">
  151. <el-button @click="cTVisible = false">取 消</el-button>
  152. <el-button type="primary" @click="saveTimeList">保 存</el-button>
  153. </span>
  154. </el-dialog>
  155. <el-dialog
  156. title="校对字幕时间"
  157. :visible.sync="compareShow"
  158. width="50%"
  159. :before-close="handleClose"
  160. top="0"
  161. >
  162. <CompareTime
  163. :data="compareData"
  164. :type="compareType"
  165. :changewordsResultList="changewordsResultList"
  166. />
  167. <span slot="footer" class="dialog-footer">
  168. <el-button @click="handleClose">取 消</el-button>
  169. <el-button :loading="compareloading" type="primary" @click="saveCompare"
  170. >确 定</el-button
  171. >
  172. </span>
  173. </el-dialog>
  174. </div>
  175. </template>
  176. <script>
  177. import {
  178. segSentences,
  179. BatchSegContent,
  180. prepareTranscribe,
  181. getWordTime,
  182. compareSenTenceTime,
  183. textCreadMp3,
  184. getContentFile,
  185. } from "@/api/ajax";
  186. const Base64 = require("js-base64").Base64;
  187. import Upload from "../../common/Upload.vue";
  188. import UploadArt from "../../common/UploadArt.vue";
  189. import ArticleChs from "./components/ArticleChs.vue";
  190. import Paragraph from "./components/ParagraphChs.vue";
  191. import Clauseresult from "./components/ClauseresultChs.vue";
  192. import Segbyword from "./components/SegbywordChs.vue";
  193. import Createtimelist from "./components/CreatetimelistChs.vue";
  194. import CompareTime from "./components/CompareTime.vue";
  195. export default {
  196. name: "ArticleTemChs",
  197. components: {
  198. Upload,
  199. UploadArt,
  200. ArticleChs,
  201. Paragraph,
  202. Clauseresult,
  203. Segbyword,
  204. Createtimelist,
  205. CompareTime,
  206. },
  207. props: ["curQue", "changeCurQue", "tmIndex"],
  208. data() {
  209. return {
  210. imageNumber: 1000,
  211. mp3Number: 1,
  212. fileCon: {
  213. img_list: [],
  214. mp3_list: [],
  215. },
  216. isPara: false,
  217. isClause: false,
  218. isByWord: false,
  219. paraIndex: 0, //段落索引
  220. cTVisible: false,
  221. loading: false,
  222. segList: null,
  223. data_structure: {
  224. type: "article_chs",
  225. name: "课文",
  226. model: 1,
  227. pyPosition: "top", //top 拼音在上面;bottom 拼音在下面
  228. mp3_list: [],
  229. img_list: [],
  230. article: "",
  231. detail: [],
  232. wordTime: [],
  233. taskId: "",
  234. checkList: [1, 2, 3],
  235. },
  236. isWordTime: false,
  237. compareType: "", //校对类型
  238. compareShow: false,
  239. compareData: null,
  240. compareloading: false,
  241. CreadMp3loading: false,
  242. };
  243. },
  244. computed: {},
  245. watch: {},
  246. //方法集合
  247. methods: {
  248. // 得到文件流
  249. getfillLiu() {
  250. this.loading = true;
  251. let _this = this;
  252. return new Promise(function (resolve, reject) {
  253. if (
  254. _this.curQue.mp3_list &&
  255. _this.curQue.mp3_list.length > 0 &&
  256. _this.curQue.mp3_list[0].id
  257. ) {
  258. let Mname = "file_store_manager-GetFileByteBase64Text";
  259. let id = _this.curQue.mp3_list[0].id
  260. .replace("[FID##", "")
  261. .replace("##FID]", "");
  262. let data = {
  263. file_id: id,
  264. };
  265. getContentFile(Mname, data).then((res) => {
  266. let taskIddata = {
  267. fileName: _this.curQue.mp3_list[0].name,
  268. speechBase64: res.base64_text,
  269. language: "ch",
  270. };
  271. prepareTranscribe(taskIddata).then((ress) => {
  272. _this.$set(_this.curQue, "taskId", ress.data.taskId);
  273. _this.loading = false;
  274. resolve();
  275. });
  276. });
  277. } else {
  278. _this.$message.warning("请先上传音频");
  279. _this.loading = false;
  280. }
  281. });
  282. },
  283. // 根据文章生成MP3
  284. CreadMp3() {
  285. let _this = this;
  286. if (_this.curQue.mp3_list.length > 0) {
  287. _this.$message.warning("已有音频,请勿重复生成");
  288. return;
  289. }
  290. if (!_this.curQue.article) {
  291. _this.$message.warning("请先输入内容,在生成音频");
  292. return;
  293. }
  294. _this.CreadMp3loading = true;
  295. textCreadMp3({
  296. text: _this.curQue.article,
  297. }).then((res) => {
  298. res.data.fileInfo.id = "[FID##" + res.data.fileInfo.file_id + "##FID]";
  299. res.data.fileInfo.name = res.data.fileInfo.file_name;
  300. let fileList = [res.data.fileInfo];
  301. _this.$set(_this.curQue, "mp3_list", fileList);
  302. _this.CreadMp3loading = false;
  303. _this.$message.success("生成成功");
  304. });
  305. },
  306. //删除生成的mp3
  307. delMp3() {
  308. this.curQue.mp3_list.splice(0, 1);
  309. },
  310. // 保存校对
  311. saveCompare() {
  312. if (this.compareType == "文字") {
  313. this.compareloading = false;
  314. return;
  315. }
  316. this.compareloading = true;
  317. compareSenTenceTime({ matchList: JSON.stringify(this.compareData) })
  318. .then((res) => {
  319. console.log(res);
  320. this.compareloading = false;
  321. this.curQue.wordTime = res.data.result;
  322. })
  323. .catch(() => {
  324. this.compareloading = false;
  325. });
  326. },
  327. // 校对时间
  328. compareTime(type) {
  329. this.compareType = type;
  330. this.compareData = JSON.parse(JSON.stringify(this.curQue.wordTime));
  331. this.compareShow = true;
  332. },
  333. handleClose() {
  334. this.compareShow = false;
  335. this.compareData = null;
  336. this.compareType = "";
  337. },
  338. // 校对每个字的时间
  339. changewordsResultList(index, item) {
  340. this.curQue.wordTime[index].wordsResultList = JSON.parse(
  341. JSON.stringify(item)
  342. );
  343. },
  344. changeMp3(fileList) {
  345. const articleImgList = JSON.parse(JSON.stringify(fileList));
  346. const articleImgRes = [];
  347. articleImgList.forEach((item) => {
  348. if (item.response) {
  349. const obj = {
  350. name: item.name,
  351. duration: item.response.file_info_list[0].media_duration,
  352. url: item.response.file_info_list[0].file_url,
  353. id: "[FID##" + item.response.file_info_list[0].file_id + "##FID]",
  354. media_duration: item.response.file_info_list[0].media_duration, //音频时长
  355. };
  356. articleImgRes.push(obj);
  357. }
  358. });
  359. this.curQue.mp3_list = JSON.parse(JSON.stringify(articleImgRes));
  360. },
  361. changeImage(file) {
  362. console.log(file);
  363. if (file.response) {
  364. const obj = {
  365. name: file.name,
  366. url: file.response.file_info_list[0].file_url,
  367. id: "[FID##" + file.response.file_info_list[0].file_id + "##FID]",
  368. imgNumber: 0,
  369. };
  370. this.curQue.img_list.push(obj);
  371. this.$forceUpdate();
  372. }
  373. },
  374. forceUpdate() {
  375. this.$forceUpdate();
  376. },
  377. delImage(index) {
  378. this.curQue.img_list.splice(index, 1);
  379. this.fileCon.img_list.splice(index, 1);
  380. },
  381. changeIsPara() {
  382. this.isPara = true;
  383. },
  384. //生成分句
  385. sureSeg() {
  386. let detail = JSON.parse(JSON.stringify(this.curQue.detail));
  387. let leg = detail.length;
  388. let flag = false;
  389. for (let i = 0; i < leg; i++) {
  390. if (!detail[i].para) {
  391. flag = true;
  392. break;
  393. }
  394. }
  395. if (!flag) {
  396. let textList = [];
  397. detail.forEach((item) => {
  398. let str = Base64.encode(item.para);
  399. textList.push(str);
  400. });
  401. this.loading = true;
  402. let data = {
  403. textList: textList,
  404. };
  405. segSentences(data).then((res) => {
  406. this.loading = false;
  407. let result = res.data.result;
  408. result.forEach((item, index) => {
  409. this.$set(this.curQue.detail[index], "sentences", item);
  410. });
  411. this.isClause = true;
  412. });
  413. } else {
  414. this.$message.warning("段落不能为空");
  415. }
  416. },
  417. changeIsClause(isClause) {
  418. this.isClause = isClause;
  419. },
  420. //生成分词
  421. segByWord(sentences, paraIndex) {
  422. console.log(sentences);
  423. this.loading = true;
  424. let textList = [];
  425. sentences.forEach((item) => {
  426. let str = Base64.encode(item);
  427. textList.push(str);
  428. });
  429. let data = {
  430. textList: textList,
  431. };
  432. BatchSegContent(data).then((res) => {
  433. this.loading = false;
  434. let list = res.data.result.list;
  435. this.$set(this.curQue.detail[paraIndex], "segList", list);
  436. console.log(this.curQue);
  437. this.segList = list;
  438. this.isByWord = true;
  439. this.paraIndex = paraIndex;
  440. });
  441. },
  442. // 上传音频文件
  443. handleChange(file, fileList) {
  444. let _this = this;
  445. _this.getBase64(file.raw).then((res) => {
  446. let base_res = res.split("base64,");
  447. let data = {
  448. fileName: file.raw.name,
  449. speechBase64: base_res[1],
  450. language: "ch",
  451. };
  452. prepareTranscribe(data).then((ress) => {
  453. _this.$set(_this.curQue, "taskId", ress.data.taskId);
  454. });
  455. });
  456. },
  457. getBase64(file) {
  458. return new Promise(function (resolve, reject) {
  459. let reader = new FileReader();
  460. let imgResult = "";
  461. reader.readAsDataURL(file);
  462. reader.onload = function () {
  463. imgResult = reader.result;
  464. };
  465. reader.onerror = function (error) {
  466. reject(error);
  467. };
  468. reader.onloadend = function () {
  469. resolve(imgResult);
  470. };
  471. });
  472. },
  473. createWordTime() {
  474. this.getfillLiu().then(() => {
  475. if (this.curQue.taskId) {
  476. let verseList = [];
  477. this.curQue.detail.forEach((item) => {
  478. verseList = verseList.concat(item.sentences);
  479. });
  480. if (verseList.length > 0) {
  481. this.isWordTime = true;
  482. let data = {
  483. taskId: this.curQue.taskId,
  484. verseList: JSON.stringify(verseList),
  485. matchType: "chinese",
  486. language: "ch",
  487. };
  488. getWordTime(data).then((res) => {
  489. this.curQue.wordTime = res.data.result;
  490. this.isWordTime = false;
  491. });
  492. }
  493. } else {
  494. this.$message.warning("请先上传音频");
  495. this.loading = false;
  496. }
  497. });
  498. },
  499. againWordTime() {
  500. this.isWordTime = false;
  501. this.$set(this.curQue, "wordTime", []);
  502. },
  503. uploadLRC() {
  504. this.cTVisible = true;
  505. },
  506. //保存字幕节点
  507. saveTimeList() {
  508. this.cTVisible = false;
  509. let detail = JSON.parse(JSON.stringify(this.$refs.createtimelist.detail));
  510. let detailRes = detail.map((item) => {
  511. let timeList = item.time_str.split("\n");
  512. item.timeList = this.handleTimeReg(timeList);
  513. return item;
  514. });
  515. this.curQue.detail = JSON.parse(JSON.stringify(detailRes));
  516. console.log(this.curQue.detail);
  517. },
  518. handleTimeReg(list) {
  519. list = list.map((item) => {
  520. let regArr = item.split("]");
  521. let reg = regArr[0];
  522. item = reg.replace("[", "");
  523. return item;
  524. });
  525. return list;
  526. },
  527. //点击字幕节点
  528. editTimeList() {
  529. this.cTVisible = true;
  530. },
  531. initCurQueData() {
  532. let res_data = JSON.parse(JSON.stringify(this.data_structure));
  533. this.changeCurQue(res_data);
  534. },
  535. },
  536. //生命周期 - 创建完成(可以访问当前this实例)
  537. created() {},
  538. //生命周期 - 挂载完成(可以访问DOM元素)
  539. mounted() {
  540. console.log("文章编辑");
  541. console.log(this.curQue);
  542. if (this.curQue) {
  543. if (!this.curQue.hasOwnProperty("checkList")) {
  544. this.$set(this.curQue, "checkList", [1, 2, 3]);
  545. }
  546. if (!this.curQue.taskId) {
  547. this.curQue.taskId = "";
  548. }
  549. if (this.curQue.detail[0].para) {
  550. this.isPara = true;
  551. }
  552. if (this.curQue.detail[0].sentences.length > 0) {
  553. this.isClause = true;
  554. }
  555. if (this.curQue.detail[0].seg_words.length > 0) {
  556. this.isByWord = true;
  557. }
  558. if (!this.curQue.img_list) {
  559. this.curQue.img_list = [];
  560. }
  561. if (!this.curQue.mp3_list) {
  562. this.curQue.mp3_list = [];
  563. }
  564. this.fileCon.img_list = JSON.parse(JSON.stringify(this.curQue.img_list));
  565. let mp3_list = JSON.parse(JSON.stringify(this.curQue.mp3_list));
  566. this.fileCon.mp3_list = mp3_list.filter((item) => item.source !== "tts");
  567. } else {
  568. this.initCurQueData();
  569. }
  570. },
  571. beforeCreate() {}, //生命周期 - 创建之前
  572. beforeMount() {}, //生命周期 - 挂载之前
  573. beforeUpdate() {}, //生命周期 - 更新之前
  574. updated() {}, //生命周期 - 更新之后
  575. beforeDestroy() {}, //生命周期 - 销毁之前
  576. destroyed() {}, //生命周期 - 销毁完成
  577. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  578. };
  579. </script>
  580. <style lang='scss' scoped>
  581. //@import url(); 引入公共css类
  582. .create_mp3_list {
  583. display: flex;
  584. justify-content: flex-start;
  585. align-items: center;
  586. > span {
  587. font-size: 16px;
  588. font-weight: bold;
  589. margin-right: 10px;
  590. }
  591. > img {
  592. width: 24px;
  593. height: 24px;
  594. cursor: pointer;
  595. }
  596. }
  597. p {
  598. margin: 0;
  599. padding: 0;
  600. }
  601. .uploadArt_list {
  602. border: 1px #ccc solid;
  603. border-bottom: 0;
  604. margin-top: 10px;
  605. > li {
  606. display: flex;
  607. justify-content: flex-start;
  608. align-items: center;
  609. border-bottom: 1px #ccc solid;
  610. > span {
  611. width: 320px;
  612. word-wrap: break-word;
  613. font-size: 14px;
  614. color: rgb(112, 110, 110);
  615. border-right: 1px #ccc solid;
  616. padding: 5px 10px;
  617. }
  618. > p {
  619. flex: 1;
  620. padding: 5px 10px;
  621. }
  622. .imgNumber {
  623. width: 80px;
  624. }
  625. .del-close {
  626. width: 24px;
  627. height: 24px;
  628. cursor: pointer;
  629. margin-right: 10px;
  630. }
  631. }
  632. }
  633. .NPC-Book-Article {
  634. > div {
  635. margin-bottom: 20px;
  636. }
  637. }
  638. .NPC-Book-model {
  639. display: flex;
  640. justify-content: flex-start;
  641. align-items: center;
  642. > span {
  643. margin: 0;
  644. }
  645. }
  646. .lrc-box {
  647. display: flex;
  648. justify-content: flex-start;
  649. align-items: center;
  650. > span {
  651. font-size: 14px;
  652. margin-right: 16px;
  653. }
  654. }
  655. </style>