TA的每日心情 | 慵懒 2021-9-1 08:46 |
---|
签到天数: 61 天 [LV.6]常住居民II
|
本帖最后由 zhangchaont 于 2021-2-20 10:53 编辑
- w3 E1 \1 Y8 h' _& u" K' e
$ x0 E% @; T- E. w为了给孩子学习英语,我把单词做成了卡片放在Anki里,但是课文却一直没有什么好的方法,在电脑上用一个复读机软件给孩子们练习,但是Mac上没有什么好用的复读机软件,所以学来学去还在最开始的几课里面打转。我本来想自己写一个复读机APP的,但是考虑到水平有限,估计得花很多时间,而且最大的问题不能利用Anki里schedule安排学习。# r, m. n8 Y4 R1 w' f! f
( E: K0 }/ S9 k/ O春节在家,我突然灵光一闪,Anki是基于PyQt5开发,而这个模块是支持一部分html、css和javascript的,如果用javascript读取字幕里面的时间戳,然后根据时间段来播放MP3,不就实现了一个简单的复读机了嘛。说干就干,因为没有javascript语言基础,都是需要什么就搜索,一步步的拼凑起来的,目前已经基本能用,成品在iOS上显示如下:( m7 _! `$ w; ^! D5 W
/ }* ?: @2 J; c# b: q1 {
macOS上的效果$ K2 f& C) n$ ?& J
% C4 Z% q: b( z) q+ h' H
4 y$ m9 B# C5 N& V. Bjs代码如下:
' z [) v0 J2 n" S7 h- const lesson = document.getElementsByClassName("items")[0].innerText;
% O3 v+ L$ F+ J/ w: ?- O8 ] - const button_next = document.createElement("button");& s. h9 Q" k; a# I& A# g
- button_next.innerHTML = '下一句';
6 v9 ?) M* k# n! R: g; f - button_next.setAttribute('row_count', "4");: ^& O3 o- o O8 s. z$ \1 Y
- let section = document.getElementsByClassName("section")[0];5 [, N$ {0 F8 c
+ a) c- [4 ]" u. A- I9 v9 _* ^- const button_repeat = document.createElement("button");6 I* D$ r. o+ C1 ?) v7 \
- button_repeat.innerHTML = '重复此句';3 }& c8 d/ r) w% A0 |9 _( v
- @" R7 k8 O! O6 u: f
- const button_previous = document.createElement("button");
( L3 Q0 s2 a6 \( b/ M - button_previous.innerHTML = '上一句';/ n* n8 x* U3 d* _
$ P+ ?$ {9 z& x- [ {! Q8 W. R5 E) P
- let div = document.createElement('div');
9 P5 L7 P* r3 @& }& ]) ^% ~+ B7 T - div.setAttribute('class', 'text');
4 V6 |+ Y5 @8 S' g! [6 ~ - section.appendChild(div);- {' i f' Q' N; |" O" Y5 I" s
- let p = document.createElement('p');
# ]' Z# n$ N5 t/ D0 o - div.appendChild(p);
) G5 {- ^ j j9 t" w* g) i/ h) H5 V7 Y
+ V& o" W' F: H: ~2 P- buttons_div = document.createElement('div');& B# W& ^0 A: N# W
- buttons_div.setAttribute('class', 'buttons');0 W3 i1 @9 p& ]. r/ s
- 9 L( `2 A, f2 M/ m6 p$ B0 m: G
- section.appendChild(buttons_div);) x; P7 u. _4 E7 ~
- ! M, y9 b% N/ G. a# Y3 g8 G
- buttons_div.appendChild(button_previous);" V J' \# ^# U3 H5 g/ m
- buttons_div.appendChild(button_repeat);
6 E8 f* L7 a0 d( T" S - buttons_div.appendChild(button_next);; y# W# R1 h9 ~) F7 w- j
5 \9 w* E4 |) l' P9 q6 r
0 i. e4 G7 b- q4 ]4 d- button_next.onclick = next;
: [7 S1 T1 H$ i8 k. u0 j - button_repeat.onclick = repeat;
. q9 c$ s# S! I4 g) i) _( ?7 e - button_previous.onclick = previous;2 a% H/ f% F" {4 u- ~4 u9 {! `
- section.onload = play;/ ^5 R+ V, a) o# B9 x, _7 L: {3 d
- ! u* O8 Q& s9 e
- function next() {
" y) b; k" V6 H, |1 u t - let index = parseInt(button_next.getAttribute('row_count')); U7 J. x8 D2 V
- index += 1;3 ], A* P" F3 U/ I: C
- button_next.setAttribute('row_count', index.toString())
, Q6 k5 X! ]% V* ^; p - play().then(r => '');% h) _$ s8 m& g# ]8 y5 D
- }* X/ K3 x4 R8 [' \7 a. M
+ d& l" G" ~; Z! z- function previous() {; H& `3 \5 j' e; r! W, J! a" v# z
- let index = parseInt(button_next.getAttribute('row_count'));5 ]& R' X6 X, O/ K" r" V
- index -= 1;' R9 p, e; g# d
- button_next.setAttribute('row_count', index.toString())* v8 {9 J: |0 U
- play().then(r => '');0 n `. H+ G2 I
- }
. S. A) V8 `: I) R2 g* O& L) H
7 J0 t' a5 B) H/ X9 M8 d- function repeat() {) U# Y# Y4 P6 _2 L8 r' G, F# d4 _2 L
- play().then(r => '');
7 N! h/ X$ d* z7 f! B - }
2 O5 v! T. p: ~* R - ) V e2 u; J4 Z# ]3 @0 e
- async function play() {* X, X0 u+ t7 o
- const file = "NCE1-" + lesson + ".lrc";
1 Y" V( I5 x l+ } - let myObject = await fetch(file);
5 A5 B* S5 Y1 b7 m7 _ z0 F - let myText = (await myObject.text()).trim();! H0 Z6 h1 L" R% B$ B, J% m! D! n
- let lines = myText.split('\n');' z( v9 G5 ~/ t* z7 h$ u
- let index = parseInt(button_next.getAttribute('row_count'));1 A3 N* R$ w: ^" Q* m
( Z4 g& X0 F: P. W; W- if (index < 4) {
d3 Z: V v1 T5 X - index = lines.length - 1;
" ?% d; x# F/ e0 J" [4 V+ O - button_next.setAttribute('row_count', index.toString());
' m/ k0 r4 ?; M5 z0 z - }
. a# ]- K2 i$ T+ Q8 f+ w7 f - if (index > lines.length - 1) {
, O5 T5 p# j) p! t* V6 m9 n2 W - index = 4;) V$ e* O* `, ] j* Q# E
- button_next.setAttribute('row_count', index.toString());
) R0 b% z6 |5 a2 u2 U - }/ G% A( R, s Q* j/ {! g& ]1 Q! M
- let current_line = lines[index];
# a3 `0 d) S+ {3 L; L - let text = current_line.slice(10, current_line.length - 1);
E! d6 A2 C4 ]0 J( r$ t - p.innerText = text;
0 p3 \9 M2 E6 p; i - if (index < (lines.length - 1)) {& r% R' I' x8 v6 w
- let next_index = index + 1;- c( a! ?0 }0 U) M/ t
- let next_line = lines[next_index];
* B/ t6 ?0 T& P6 Q; ]) { - let current_time = current_line.slice(1, 9);! ~8 x# @/ N) D. w' x0 r$ S
- let current_time_min_sec = current_time.split(':');' G& _; w' \! Z
- let start = parseFloat(current_time_min_sec[0]) * 60 + parseFloat(current_time_min_sec[1]);
3 W& r% z" e$ S( e+ i5 ] - let next_time = next_line.slice(1, 9);
: r6 j* R9 ~+ l* A6 \& d9 _! u4 a6 r - let next_time_min_sec = next_time.split(':');, h) x+ y9 M7 M( h
- let end = parseFloat(next_time_min_sec[0]) * 60 + parseFloat(next_time_min_sec[1]) - 0.25;& R1 B# d) X8 @3 V) i8 b' H
- let audio = new Audio("NCE1-" + lesson + ".mp3" + "#t=" + start + "," + end);: m8 B; ?/ ^4 P3 ?0 u, c. Y
- const play1 = audio.play();
: U$ u& @+ h4 A( v - } else {7 G) m" M, j$ ]* Z. P
- let current_time = current_line.slice(1, 9);
4 ]9 L; w- ^+ \ - let current_time_min_sec = current_time.split(':');- l' W3 I6 H0 s# Y/ @
- let start = parseFloat(current_time_min_sec[0]) * 60 + parseFloat(current_time_min_sec[1]);; ]3 k7 s* e1 f: P" f
- let audio = new Audio("NCE1-" + lesson + ".mp3" + "#t=" + start);
6 d, }1 x6 L1 E; M7 q1 R - const play2 = audio.play();7 ]% e0 X+ _& G2 b8 `3 v
- }" x9 ?+ m- @% {
- }
复制代码
* G$ c$ E. g: j, u
- c$ H: u. h u使用的时候,把下面网盘链接里面的Anki卡片导入,然后把新概念的音频和字幕文件拷贝到Anki的collection.media文件夹里面,如果不知道media文件夹的位置在网上搜索一下。/ v, C( r; w! L; v% w& V0 J) U
3 ], \/ O' @3 \+ ]* |7 q
- /*区块全局样式*/
% [- L8 q0 s' f# x - .section {
* J9 T! D% J" G/ z0 _ - background-color : #f6f6f6; /*背景颜色-#f6f6f6*/2 ~0 a. e- o8 n% ^2 Y# A
- border : 2px solid #3f3f41; /*边缘样式-实线2px*/$ c- z) U' K! l+ P5 a. V: |
- border-radius : 3px; /*圆角幅度-3px*/
% Y8 A F: y0 L7 c6 y* H) Y - margin : 8px 8px; /*上下间隔-8px*/
4 K6 {* s/ ?7 ]$ c) c/ r) N* T - display : flex;
- T/ p0 n9 E+ e4 t+ _8 S3 U) ^ - flex-direction : column;+ U) H% c; A6 B' o% k% |
- height: 95vh;$ ^. I* o( r. }6 P
- }
1 e& @3 r5 K X3 {) n' ?+ o u
9 F# [! m2 _! O! C- j$ S- m& ^- /*区块全局样式*/; Y" y8 W% g& c& q; j% R0 A! p
- .mobile .section {
" U. g7 m1 n3 W - background-color : #f6f6f6; /*背景颜色-#f6f6f6*/
! T3 h7 Q& ?; A' j4 ]& I7 a9 w1 S - border : 2px solid #3f3f41; /*边缘样式-实线2px*/7 v4 A$ D: p0 R
- border-radius : 3px; /*圆角幅度-3px*/
" L5 e' t0 Q4 i1 K5 D! J - margin : 8px 8px; /*上下间隔-8px*/ H6 S! F3 K9 {# V) u' v- Z
- display : flex;( ]4 j/ F: Q! C/ z' {
- flex-direction : column;
* f+ q/ p$ W. v$ c8 }9 Y" n- U. f2 ^ - height: 77vh;
{7 W' n/ H4 c- J0 F - }
复制代码
& M, B# Z. m7 O6 x在模板里面的css部分,可以调节整个区块的大小,修改height后面的数值来调节。前面有.mobile的是对移动设备的设置。( w4 c8 v% ~% k7 X+ b! k
e8 I% x: ]% }2 L4 k5 Y1 Y
你也可以把这个模板稍加修改就可以添加新概念后面的几本书。
& H7 z5 n& y% G ^8 r4 u# n* T: j7 ]* s, v& n! [, g# X
% m- s4 K" E- k* \
2 B6 y5 o0 H! c+ }" K4 ~6 I注意,因为iOS版本的Anki不会自动重新加载js,所以到第二张卡片的时候就会按钮显示不出来,退到deck界面再进去就可以了。 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?免费注册
x
评分
-
2
查看全部评分
-
|