Commit 78402008 authored by liujiangnan's avatar liujiangnan

feat: 逐字高亮

parent f5e2f981
我有一个JSON数据,字段解释如下:
```
{
"audio_points": {
"说明": "音频相关的信息",
"字段": {
"audio_url": "音频文件的URL地址",
"points": {
"说明": "音频断点信息数组",
"包含字段": {
"start": "该段音频的开始时间(秒)",
"end": "该段音频的结束时间(秒)",
"text": "该段音频对应的英文文本",
"words": {
"说明": "单词级别的时间轴信息",
"包含字段": {
"start": "单词开始时间",
"end": "单词结束时间",
"word": "具体单词"
}
}
}
}
}
},
"pages": {
"说明": "书籍页面信息数组",
"字段": {
"image_url": "页面图片的URL地址",
"page": "页码",
"start": "该页面内容在音频中的开始时间",
"end": "该页面内容在音频中的结束时间",
"groups": {
"说明": "页面中的文本组信息",
"包含字段": {
"sentence": "识别出的英文句子",
"sentence_cn": "对应的中文翻译",
"start": "句子在音频中的开始时间",
"end": "句子在音频中的结束时间",
"reason": "时间戳缺失或特殊情况的解释说明",
"group": {
"说明": "文本在图片中的位置信息",
"包含字段": {
"rect": {
"x": "文本框左上角的X坐标(相对值)",
"y": "文本框左上角的Y坐标(相对值)",
"width": "文本框的宽度(相对值)",
"height": "文本框的高度(相对值)"
},
"text": "实际文本内容"
}
}
}
}
}
}
}
```
# 绘本阅读器
# 需求
我希望你基于 ./play/index.html ./play/index.css ./play/index.js 帮我实现上面数据的播放功能,主要包含如下:
1、分页展示图片,每一页放一张图片。图片按照页面尺寸适配,如果是长图则左右留白,如果是宽图则上下留白
2、页面的左下角浮动两个按钮,一个是上一页,一个是下一页。
3、播放音频,有播放和暂停的按钮,也浮动在左下角,不用显示音频元素以及音频的进度条等。
4、当音频播放到哪一页,图片分页就翻到对应页。
5、翻页动画做成左右滑动然后渐入渐出。
6、手动点击上一页/下一页如果音频正在播放则立即跳转到对应页的开始时间进行播放,如果音频是暂停或者未播放的状态,这个时候点击播放则也是在这一页的开始时间进行播放,如果音频正好暂停在这一页的某个时间,此时点击播放就是继续播放,不用跳回到本页的开始时间。
7、页面的正下方居中浮动音频对应的字幕(audio_points.points.text),音频播放到哪一句就显示哪一句,播放完就隐藏,字幕的样式用 0.2透明度的黑色背景,然后字体用白色。
8、在图片上画蓝色的矩形框,数据在pages.groups[].group.rect里,是相对于图片宽高的归一化坐标,当音频读到某个矩形框的时候就显示,过了就消失。
9、当音频播放到最后结束,跳回到第一页,音频也从零开始。
基于JSON数据实现的绘本阅读器系统,支持音频同步播放、页面切换、文本高亮等功能。
# 技术框架描述
## 功能特性
Vue2、element-ui 2.12、jQuery 1.12.3
1. **分页展示图片** - 每一页显示一张图片,图片按照页面尺寸适配
2. **页面控制** - 左下角浮动上一页/下一页按钮
3. **音频播放控制** - 播放/暂停按钮,浮动在左下角
4. **音频页面同步** - 音频播放到哪一页就显示对应页面
5. **智能跳转** - 手动切换页面时,如果音频正在播放则跳转到对应页面的开始时间
6. **蓝色矩形框** - 当音频读到某个矩形框时显示,过了就消失
7. **单词高亮** - 当音频读到某个单词时显示黄色背景高亮,切换页时高亮消失
8. **循环播放** - 音频播放结束后自动回到第一页重新开始
都是通过CDN的方式引入好的,你就不要用组件的形式新建其他文件了,都在 ./play/index.js 通过new VUE()的方式 全部实现逻辑部分就好。
## 技术栈
我还给你提供了一个真实的数据文件 /form/defaultData.json
- Vue 2
- Element UI 2.12
- jQuery 1.12.3
- 原生HTML5 Audio API
记得必须要用 Vue2 来实现
## 数据结构
JSON数据包含以下字段:
- `audio_url`: 音频文件地址
- `pages`: 页面数组,每个页面包含:
- `image_url`: 图片地址
- `page`: 页面编号
- `start`: 页面开始时间(秒)
- `end`: 页面结束时间(秒)
- `groups`: 句子组数组,包含文本位置和时间信息
## 使用方法
1. 启动本地服务器:
```bash
cd play
python3 -m http.server 8000
```
2. 打开浏览器访问:`http://localhost:8000`
3. 使用控制按钮:
- 点击播放按钮开始播放音频
- 点击暂停按钮暂停播放
- 点击上一页/下一页按钮切换页面
- 观察文本高亮和矩形框显示效果
## 文件结构
- `index.html` - 主页面模板
- `index.css` - 样式文件
- `index.js` - Vue应用逻辑
- `defaultData_1.json` - 示例数据文件
- `schema.json` - 数据格式定义
## 注意事项
- 确保音频文件和图片文件可以正常访问
- 数据文件需要符合schema.json定义的格式
- 浏览器需要支持HTML5 Audio API
{
"audio_points": {
"audio_url": "https://staging-teach.cdn.ireadabc.com/23fdd207b9e3b382803c8cea33f939c0_l.mp3",
"points": [
{
"end": 5.31,
"text": "Baby Animals: Super Cute Reptiles.",
"start": 0.63,
"words": [
{
"end": 1.07,
"word": "Baby",
"start": 0.63
},
{
"end": 1.95,
"word": "Animals:",
"start": 1.25
},
{
"end": 3.22,
"word": "Super",
"start": 2.77
},
{
"end": 3.91,
"word": "Cute",
"start": 3.46
},
{
"end": 5.13,
"word": "Reptiles.",
"start": 4.19
}
]
},
{
"end": 7.93,
"text": "A Crabtree Roots Book.",
"start": 5.83,
"words": [
{
"end": 5.91,
"word": "A",
"start": 5.83
},
{
"end": 6.79,
"word": "Crabtree",
"start": 6.01
},
{
"end": 7.25,
"word": "Roots",
"start": 6.87
},
{
"end": 7.75,
"word": "Book.",
"start": 7.31
}
]
},
{
"end": 9.91,
"text": "By Amy Culliford.",
"start": 8.23,
"words": [
{
"end": 8.42,
"word": "By",
"start": 8.23
},
{
"end": 8.85,
"word": "Amy",
"start": 8.51
},
{
"end": 9.73,
"word": "Culliford.",
"start": 8.93
}
]
},
{
"end": 15.43,
"text": "There are many different kinds of baby reptiles.",
"start": 11.46,
"words": [
{
"end": 11.69,
"word": "There",
"start": 11.46
},
{
"end": 11.86,
"word": "are",
"start": 11.75
},
{
"end": 12.43,
"word": "many",
"start": 12.03
},
{
"end": 13,
"word": "different",
"start": 12.61
},
{
"end": 13.55,
"word": "kinds",
"start": 13.07
},
{
"end": 13.75,
"word": "of",
"start": 13.57
},
{
"end": 14.23,
"word": "baby",
"start": 13.81
},
{
"end": 15.25,
"word": "reptiles.",
"start": 14.29
}
]
},
{
"end": 21.62,
"text": "Some baby reptiles are big, and some are small.",
"start": 16.47,
"words": [
{
"end": 16.79,
"word": "Some",
"start": 16.47
},
{
"end": 17.22,
"word": "baby",
"start": 16.85
},
{
"end": 17.99,
"word": "reptiles",
"start": 17.26
},
{
"end": 18.23,
"word": "are",
"start": 18.07
},
{
"end": 18.84,
"word": "big,",
"start": 18.34
},
{
"end": 19.78,
"word": "and",
"start": 19.63
},
{
"end": 20.27,
"word": "some",
"start": 19.87
},
{
"end": 20.76,
"word": "are",
"start": 20.6
},
{
"end": 21.44,
"word": "small.",
"start": 20.81
}
]
},
{
"end": 29.65,
"text": "Some baby reptiles live on land, and some can live in water.",
"start": 23.43,
"words": [
{
"end": 23.85,
"word": "Some",
"start": 23.43
},
{
"end": 24.3,
"word": "baby",
"start": 23.92
},
{
"end": 25.13,
"word": "reptiles",
"start": 24.35
},
{
"end": 25.6,
"word": "live",
"start": 25.27
},
{
"end": 25.85,
"word": "on",
"start": 25.65
},
{
"end": 26.45,
"word": "land,",
"start": 25.92
},
{
"end": 27.34,
"word": "and",
"start": 27.13
},
{
"end": 27.81,
"word": "some",
"start": 27.37
},
{
"end": 28.11,
"word": "can",
"start": 27.97
},
{
"end": 28.55,
"word": "live",
"start": 28.19
},
{
"end": 28.86,
"word": "in",
"start": 28.71
},
{
"end": 29.47,
"word": "water.",
"start": 28.93
}
]
},
{
"end": 36.08,
"text": "Baby crocodiles live on land and in water.",
"start": 31.29,
"words": [
{
"end": 31.68,
"word": "Baby",
"start": 31.29
},
{
"end": 32.68,
"word": "crocodiles",
"start": 31.76
},
{
"end": 33.27,
"word": "live",
"start": 32.91
},
{
"end": 33.57,
"word": "on",
"start": 33.36
},
{
"end": 34.06,
"word": "land",
"start": 33.61
},
{
"end": 34.88,
"word": "and",
"start": 34.34
},
{
"end": 35.27,
"word": "in",
"start": 35.11
},
{
"end": 35.9,
"word": "water.",
"start": 35.36
}
]
},
{
"end": 40.74,
"text": "Most baby crocodiles are small.",
"start": 37.81,
"words": [
{
"end": 38.21,
"word": "Most",
"start": 37.81
},
{
"end": 38.61,
"word": "baby",
"start": 38.29
},
{
"end": 39.55,
"word": "crocodiles",
"start": 38.7
},
{
"end": 39.84,
"word": "are",
"start": 39.61
},
{
"end": 40.56,
"word": "small.",
"start": 39.93
}
]
},
{
"end": 43.99,
"text": "They can be green or gray.",
"start": 41.25,
"words": [
{
"end": 41.43,
"word": "They",
"start": 41.25
},
{
"end": 41.65,
"word": "can",
"start": 41.52
},
{
"end": 41.83,
"word": "be",
"start": 41.71
},
{
"end": 42.59,
"word": "green",
"start": 41.91
},
{
"end": 43.13,
"word": "or",
"start": 42.89
},
{
"end": 43.81,
"word": "gray.",
"start": 43.25
}
]
},
{
"end": 51.4,
"text": "All baby crocodiles have tails that help them move through water.",
"start": 45.45,
"words": [
{
"end": 45.93,
"word": "All",
"start": 45.45
},
{
"end": 46.43,
"word": "baby",
"start": 46.11
},
{
"end": 47.39,
"word": "crocodiles",
"start": 46.52
},
{
"end": 47.72,
"word": "have",
"start": 47.41
},
{
"end": 48.39,
"word": "tails",
"start": 47.79
},
{
"end": 48.88,
"word": "that",
"start": 48.75
},
{
"end": 49.19,
"word": "help",
"start": 48.93
},
{
"end": 49.47,
"word": "them",
"start": 49.23
},
{
"end": 50.15,
"word": "move",
"start": 49.63
},
{
"end": 50.56,
"word": "through",
"start": 50.29
},
{
"end": 51.22,
"word": "water.",
"start": 50.63
}
]
},
{
"end": 58.12,
"text": "Baby lizards can be big or small when they are young.",
"start": 52.87,
"words": [
{
"end": 53.27,
"word": "Baby",
"start": 52.87
},
{
"end": 54.03,
"word": "lizards",
"start": 53.37
},
{
"end": 54.4,
"word": "can",
"start": 54.25
},
{
"end": 54.56,
"word": "be",
"start": 54.45
},
{
"end": 55.09,
"word": "big",
"start": 54.63
},
{
"end": 55.68,
"word": "or",
"start": 55.37
},
{
"end": 56.39,
"word": "small",
"start": 55.77
},
{
"end": 56.95,
"word": "when",
"start": 56.79
},
{
"end": 57.18,
"word": "they",
"start": 57
},
{
"end": 57.31,
"word": "are",
"start": 57.19
},
{
"end": 57.94,
"word": "young.",
"start": 57.39
}
]
},
{
"end": 64.36,
"text": "Most baby lizards are green, yellow, or brown.",
"start": 59.71,
"words": [
{
"end": 60.13,
"word": "Most",
"start": 59.71
},
{
"end": 60.55,
"word": "baby",
"start": 60.19
},
{
"end": 61.25,
"word": "lizards",
"start": 60.63
},
{
"end": 61.45,
"word": "are",
"start": 61.29
},
{
"end": 62.1,
"word": "green,",
"start": 61.53
},
{
"end": 62.95,
"word": "yellow,",
"start": 62.41
},
{
"end": 63.45,
"word": "or",
"start": 63.29
},
{
"end": 64.18,
"word": "brown.",
"start": 63.55
}
]
},
{
"end": 69.17,
"text": "They can also be blue, red, or orange.",
"start": 65.04,
"words": [
{
"end": 65.18,
"word": "They",
"start": 65.04
},
{
"end": 65.37,
"word": "can",
"start": 65.23
},
{
"end": 65.76,
"word": "also",
"start": 65.4
},
{
"end": 66,
"word": "be",
"start": 65.86
},
{
"end": 66.59,
"word": "blue,",
"start": 66.08
},
{
"end": 67.66,
"word": "red,",
"start": 67.18
},
{
"end": 68.13,
"word": "or",
"start": 67.97
},
{
"end": 68.99,
"word": "orange.",
"start": 68.27
}
]
},
{
"end": 74.29,
"text": "All baby lizards have four legs.",
"start": 71.04,
"words": [
{
"end": 71.38,
"word": "All",
"start": 71.04
},
{
"end": 71.79,
"word": "baby",
"start": 71.45
},
{
"end": 72.43,
"word": "lizards",
"start": 71.87
},
{
"end": 72.69,
"word": "have",
"start": 72.5
},
{
"end": 73.19,
"word": "four",
"start": 72.79
},
{
"end": 74.11,
"word": "legs.",
"start": 73.43
}
]
},
{
"end": 81.82,
"text": "Baby snakes start out small, but can grow to be really long.",
"start": 75.95,
"words": [
{
"end": 76.33,
"word": "Baby",
"start": 75.95
},
{
"end": 77.08,
"word": "snakes",
"start": 76.45
},
{
"end": 77.63,
"word": "start",
"start": 77.36
},
{
"end": 77.87,
"word": "out",
"start": 77.65
},
{
"end": 78.54,
"word": "small,",
"start": 77.91
},
{
"end": 79.19,
"word": "but",
"start": 79.01
},
{
"end": 79.41,
"word": "can",
"start": 79.23
},
{
"end": 79.8,
"word": "grow",
"start": 79.43
},
{
"end": 80,
"word": "to",
"start": 79.86
},
{
"end": 80.18,
"word": "be",
"start": 80.04
},
{
"end": 80.81,
"word": "really",
"start": 80.31
},
{
"end": 81.64,
"word": "long.",
"start": 81.09
}
]
},
{
"end": 86.86,
"text": "Many baby snakes have scales.",
"start": 83.65,
"words": [
{
"end": 84,
"word": "Many",
"start": 83.65
},
{
"end": 84.44,
"word": "baby",
"start": 84.08
},
{
"end": 85.13,
"word": "snakes",
"start": 84.54
},
{
"end": 85.77,
"word": "have",
"start": 85.36
},
{
"end": 86.68,
"word": "scales.",
"start": 85.91
}
]
},
{
"end": 92.25,
"text": "Scales help baby snakes keep water in.",
"start": 88.58,
"words": [
{
"end": 89.23,
"word": "Scales",
"start": 88.58
},
{
"end": 89.54,
"word": "help",
"start": 89.27
},
{
"end": 90,
"word": "baby",
"start": 89.65
},
{
"end": 90.55,
"word": "snakes",
"start": 90.07
},
{
"end": 90.94,
"word": "keep",
"start": 90.65
},
{
"end": 91.67,
"word": "water",
"start": 91.01
},
{
"end": 92.07,
"word": "in.",
"start": 91.72
}
]
},
{
"end": 95.73,
"text": "They also help them to move around.",
"start": 92.97,
"words": [
{
"end": 93.11,
"word": "They",
"start": 92.97
},
{
"end": 93.47,
"word": "also",
"start": 93.15
},
{
"end": 93.77,
"word": "help",
"start": 93.54
},
{
"end": 94.22,
"word": "them",
"start": 93.79
},
{
"end": 94.41,
"word": "to",
"start": 94.22
},
{
"end": 94.81,
"word": "move",
"start": 94.43
},
{
"end": 95.55,
"word": "around.",
"start": 94.81
}
]
},
{
"end": 101.28,
"text": "All baby snakes say, Hiss!",
"start": 97.59,
"words": [
{
"end": 98.03,
"word": "All",
"start": 97.59
},
{
"end": 98.54,
"word": "baby",
"start": 98.18
},
{
"end": 99.18,
"word": "snakes",
"start": 98.63
},
{
"end": 99.73,
"word": "say,",
"start": 99.36
},
{
"end": 101.28,
"word": "Hiss!",
"start": 99.73
}
]
}
]
},
"pages": [
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0001_f738aca5ba90bf65172eb28f897f89f3@1080p.jpeg",
"page": "0",
"start": 0.63,
"end": 5.31,
"groups": [
{
"sentence": "L BABY ANIMALS SNPER CUT uapbila, AMY CULLIFORD",
"sentence_cn": "L 宝宝动物 SNPER 剪裁 uapbila,艾米·卡利福德",
"start": 0.63,
"end": 5.31,
"reason": "部分文本匹配音频内容中的'Baby Animals: Super Cute Reptiles.'('BABY ANIMALS SNPER CUT'可能是音频文本的变形/误识别)",
"group": [
{
"rect": {
"x": "0.094",
"y": "0.057",
"width": "0.129",
"height": "0.061"
},
"text": "L"
},
{
"rect": {
"x": "0.298",
"y": "0.053",
"width": "0.413",
"height": "0.043"
},
"text": "BABY ANIMALS"
},
{
"rect": {
"x": "0.365",
"y": "0.121",
"width": "0.256",
"height": "0.056"
},
"text": "SNPER CUT"
},
{
"rect": {
"x": "0.106",
"y": "0.161",
"width": "0.802",
"height": "0.235"
},
"text": "uapbila,"
},
{
"rect": {
"x": "0.429",
"y": "0.351",
"width": "0.208",
"height": "0.018"
},
"text": "AMY CULLIFORD"
}
]
},
{
"sentence": "N Crabtree Roots",
"sentence_cn": "N 克拉布特里·鲁茨",
"start": null,
"end": null,
"reason": "未在音频内容中找到匹配文本,可能是未朗读的页码/标题/作者信息(如'Crabtree'为出版社名)",
"group": [
{
"rect": {
"x": "0.783",
"y": "0.855",
"width": "0.074",
"height": "0.045"
},
"text": "N"
},
{
"rect": {
"x": "0.783",
"y": "0.898",
"width": "0.081",
"height": "0.015"
},
"text": "Crabtree"
},
{
"rect": {
"x": "0.766",
"y": "0.911",
"width": "0.117",
"height": "0.026"
},
"text": "Roots"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0002_4db89af97bf7aab0cb4116a4364033eb@1080p.jpeg",
"page": "1",
"start": null,
"end": null,
"groups": []
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0003_418b75dce5a3834b0dd6aec54dd2780d@1080p.jpeg",
"page": "2",
"start": 5.83,
"end": 7.93,
"groups": [
{
"sentence": "BABY ANMALS SNPER CUT eeptta, AMY CULLIFORD",
"sentence_cn": "幼崽动物 SNPER 切割 eeptta,艾米·卡利福德",
"start": null,
"end": null,
"reason": "音频内容中不存在与文本中'BABY ANMALS SNPER CUT eeptta'或'AMY CULLIFORD'相关的任何单词或短语,可能为页码、标注或未朗读的乱码内容",
"group": [
{
"rect": {
"x": "0.272",
"y": "0.061",
"width": "0.417",
"height": "0.044"
},
"text": "BABY ANMALS"
},
{
"rect": {
"x": "0.339",
"y": "0.130",
"width": "0.259",
"height": "0.055"
},
"text": "SNPER CUT"
},
{
"rect": {
"x": "0.077",
"y": "0.172",
"width": "0.807",
"height": "0.233"
},
"text": "eeptta,"
},
{
"rect": {
"x": "0.379",
"y": "0.373",
"width": "0.222",
"height": "0.019"
},
"text": "AMY CULLIFORD"
}
]
},
{
"sentence": "A Crabtree Roots Plus Book",
"sentence_cn": "一本克拉布特里根源加强版书籍",
"start": 5.83,
"end": 7.75,
"reason": "文本'A Crabtree Roots Book'与音频文本高度匹配(仅差'Plus'一词),推测为同一句子,可能因音频版本差异或文本更新导致微小不同",
"group": [
{
"rect": {
"x": "0.167",
"y": "0.763",
"width": "0.702",
"height": "0.037"
},
"text": "A Crabtree Roots Plus Book"
}
]
},
{
"sentence": "Crabtree Publishing crabtreebooks.",
"sentence_cn": "克拉布特里出版社 crabtreebooks.",
"start": null,
"end": null,
"reason": "音频中未包含'Publishing'或'crabtreebooks'相关内容,可能为版权声明或未朗读的出版信息",
"group": [
{
"rect": {
"x": "0.400",
"y": "0.897",
"width": "0.232",
"height": "0.023"
},
"text": "Crabtree Publishing"
},
{
"rect": {
"x": "0.431",
"y": "0.926",
"width": "0.133",
"height": "0.013"
},
"text": "crabtreebooks."
}
]
},
{
"sentence": "com",
"sentence_cn": "com",
"start": null,
"end": null,
"reason": "音频中未包含'com'相关内容,可能为网址后缀或未朗读的文本元素",
"group": [
{
"rect": {
"x": "0.564",
"y": "0.926",
"width": "0.035",
"height": "0.013"
},
"text": "com"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0004_f492001043b24fc5c208593b16ce5de5@1080p.jpeg",
"page": "3",
"start": null,
"end": null,
"groups": []
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0005_b6ac0b13c5d81e282838d9bfa5362829@1080p.jpeg",
"page": "4",
"start": 11.46,
"end": 15.43,
"groups": [
{
"sentence": "There are many different kinds of baby reptiles.",
"sentence_cn": "有许多不同种类的幼年爬行动物。",
"start": 11.46,
"end": 15.43,
"reason": null,
"group": [
{
"rect": {
"x": "0.108",
"y": "0.722",
"width": "0.819",
"height": "0.045"
},
"text": "There are many different"
},
{
"rect": {
"x": "0.106",
"y": "0.789",
"width": "0.755",
"height": "0.048"
},
"text": "kinds of baby reptiles."
}
]
},
{
"sentence": "3",
"sentence_cn": "3",
"start": null,
"end": null,
"reason": "音频数据中未找到文本内容为'3'的对应句子,可能是页码标记或非朗读内容",
"group": [
{
"rect": {
"x": "0.900",
"y": "0.919",
"width": "0.032",
"height": "0.033"
},
"text": "3"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0006_53360e590ecd6e80b8aebcd4b35dbb6f@1080p.jpeg",
"page": "5",
"start": 16.47,
"end": 21.62,
"groups": [
{
"sentence": "Some baby reptiles are big, and some are small.",
"sentence_cn": "有些幼年爬行动物体型很大,有些则很小。",
"start": 16.47,
"end": 21.62,
"reason": null,
"group": [
{
"rect": {
"x": "0.089",
"y": "0.085",
"width": "0.648",
"height": "0.053"
},
"text": "Some baby reptiles"
},
{
"rect": {
"x": "0.091",
"y": "0.153",
"width": "0.628",
"height": "0.048"
},
"text": "are big, and some"
},
{
"rect": {
"x": "0.092",
"y": "0.223",
"width": "0.324",
"height": "0.041"
},
"text": "are small."
}
]
},
{
"sentence": "A",
"sentence_cn": "A",
"start": null,
"end": null,
"reason": "该句子可能为页码标记/段落标记/非朗读内容,音频数据中未包含此短句的发音时间戳",
"group": [
{
"rect": {
"x": "0.454",
"y": "0.601",
"width": "0.207",
"height": "0.108"
},
"text": "A"
}
]
},
{
"sentence": "4",
"sentence_cn": "4",
"start": null,
"end": null,
"reason": "该句子可能为页码标记/段落标记/非朗读内容,音频数据中未包含此短句的发音时间戳",
"group": [
{
"rect": {
"x": "0.071",
"y": "0.921",
"width": "0.033",
"height": "0.030"
},
"text": "4"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0007_1fa7be9fa8ec38be5ff551a3c1cd05c8@1080p.jpeg",
"page": "6",
"start": null,
"end": null,
"groups": []
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0008_ebe0483eabdf5e10e75927e039dc8f52@1080p.jpeg",
"page": "7",
"start": 23.43,
"end": 29.65,
"groups": [
{
"sentence": "Some baby reptiles live on land, and some can live in water.",
"sentence_cn": "有些幼年爬行动物生活在陆地上,有些则可以生活在水里。",
"start": 23.43,
"end": 29.65,
"reason": null,
"group": [
{
"rect": {
"x": "0.083",
"y": "0.685",
"width": "0.774",
"height": "0.054"
},
"text": "Some baby reptiles live"
},
{
"rect": {
"x": "0.085",
"y": "0.756",
"width": "0.779",
"height": "0.042"
},
"text": "on land, and some can"
},
{
"rect": {
"x": "0.083",
"y": "0.825",
"width": "0.418",
"height": "0.039"
},
"text": "live in water."
}
]
},
{
"sentence": "6",
"sentence_cn": "6",
"start": null,
"end": null,
"reason": "未匹配到对应音频片段,可能原因为:1. 该内容为页码或非朗读元素;2. 音频数据未完整提供;3. 文本与音频实际内容存在差异(如标点/数字格式不一致)",
"group": [
{
"rect": {
"x": "0.069",
"y": "0.917",
"width": "0.037",
"height": "0.035"
},
"text": "6"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0009_61bb717ec881855b9f13ed91d6a95b05@1080p.jpeg",
"page": "8",
"start": null,
"end": null,
"groups": []
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0010_478a6974d502fe9e3eed203f4df4d404@1080p.jpeg",
"page": "9",
"start": 31.29,
"end": 36.08,
"groups": [
{
"sentence": "Baby crocodiles live on land and in water.",
"sentence_cn": "幼年鳄鱼生活在陆地和水中。",
"start": 31.29,
"end": 36.08,
"reason": null,
"group": [
{
"rect": {
"x": "0.089",
"y": "0.742",
"width": "0.765",
"height": "0.048"
},
"text": "Baby crocodiles live on"
},
{
"rect": {
"x": "0.091",
"y": "0.812",
"width": "0.587",
"height": "0.038"
},
"text": "land and in water."
}
]
},
{
"sentence": "8",
"sentence_cn": "8",
"start": null,
"end": null,
"reason": "该句可能为未朗读的页码标记或非文本内容(如纯数字),音频数据中未包含对应时间信息",
"group": [
{
"rect": {
"x": "0.074",
"y": "0.922",
"width": "0.028",
"height": "0.028"
},
"text": "8"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0011_2a8fbb6eee171e7b0b119a46d69c079c@1080p.jpeg",
"page": "10",
"start": 37.81,
"end": 43.99,
"groups": [
{
"sentence": "Most baby crocodiles are small.",
"sentence_cn": "大多数小鳄鱼都很小。",
"start": 37.81,
"end": 40.74,
"reason": "",
"group": [
{
"rect": {
"x": "0.122",
"y": "0.667",
"width": "0.675",
"height": "0.049"
},
"text": "Most baby crocodiles"
},
{
"rect": {
"x": "0.125",
"y": "0.738",
"width": "0.312",
"height": "0.042"
},
"text": "are small."
}
]
},
{
"sentence": " They can be green or gray.",
"sentence_cn": "它们可以是绿色或灰色。",
"start": 41.25,
"end": 43.99,
"reason": "",
"group": [
{
"rect": {
"x": "0.428",
"y": "0.738",
"width": "0.431",
"height": "0.042"
},
"text": " They can be"
},
{
"rect": {
"x": "0.123",
"y": "0.809",
"width": "0.446",
"height": "0.043"
},
"text": "green or gray."
}
]
},
{
"sentence": "O",
"sentence_cn": "O",
"start": null,
"end": null,
"reason": "单个字母'O'可能是非朗读内容(如页码/口误/校对标记),且音频数据仅包含前两句话的时间轴",
"group": [
{
"rect": {
"x": "0.897",
"y": "0.917",
"width": "0.035",
"height": "0.034"
},
"text": "O"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0012_731fe3e0198a95b62e9d9d283619457e@1080p.jpeg",
"page": "11",
"start": null,
"end": null,
"groups": []
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0013_8f032813da23758cfea30125729927fe@1080p.jpeg",
"page": "12",
"start": 45.45,
"end": 51.4,
"groups": [
{
"sentence": "All baby crocodiles have tails that help them move through water.",
"sentence_cn": "所有小鳄鱼都有尾巴,帮助它们在水中移动。",
"start": 45.45,
"end": 51.4,
"reason": null,
"group": [
{
"rect": {
"x": "0.161",
"y": "0.531",
"width": "0.637",
"height": "0.049"
},
"text": "All baby crocodiles"
},
{
"rect": {
"x": "0.158",
"y": "0.594",
"width": "0.673",
"height": "0.053"
},
"text": "have tails that help"
},
{
"rect": {
"x": "0.156",
"y": "0.664",
"width": "0.668",
"height": "0.050"
},
"text": "them move through"
},
{
"rect": {
"x": "0.158",
"y": "0.738",
"width": "0.198",
"height": "0.038"
},
"text": "water."
}
]
},
{
"sentence": "11",
"sentence_cn": "11",
"start": null,
"end": null,
"reason": "音频数据中未找到该句对应内容,可能为页面编码/非朗读内容/转录遗漏",
"group": [
{
"rect": {
"x": "0.895",
"y": "0.917",
"width": "0.041",
"height": "0.035"
},
"text": "11"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0014_b005f2cd36b7d6edfd1b9d0ce261350e@1080p.jpeg",
"page": "13",
"start": 52.87,
"end": 58.12,
"groups": [
{
"sentence": "Baby lizards can be big or small when they are young.",
"sentence_cn": "小蜥蜴在幼年时可能体型或大或小。",
"start": 52.87,
"end": 58.12,
"reason": null,
"group": [
{
"rect": {
"x": "0.089",
"y": "0.422",
"width": "0.686",
"height": "0.047"
},
"text": "Baby lizards can be"
},
{
"rect": {
"x": "0.086",
"y": "0.490",
"width": "0.617",
"height": "0.048"
},
"text": "big or small when"
},
{
"rect": {
"x": "0.084",
"y": "0.558",
"width": "0.527",
"height": "0.054"
},
"text": "they are young."
}
]
},
{
"sentence": "12",
"sentence_cn": "12",
"start": null,
"end": null,
"reason": "未在音频数据中找到匹配的文本段落。可能原因:该内容为页码/非朗读符号,或音频数据未完整提供。",
"group": [
{
"rect": {
"x": "0.059",
"y": "0.917",
"width": "0.056",
"height": "0.037"
},
"text": "12"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0015_6b2244c6c790546aa138c65485cabb5f@1080p.jpeg",
"page": "14",
"start": null,
"end": null,
"groups": []
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0016_3361056206785f07924a0318da0f4f4e@1080p.jpeg",
"page": "15",
"start": 59.71,
"end": 69.17,
"groups": [
{
"sentence": "sa",
"sentence_cn": "sa",
"start": null,
"end": null,
"reason": "未找到匹配的音频片段,可能原因为非朗读内容(如页码、乱码或非文本标记)",
"group": [
{
"rect": {
"x": "0.520",
"y": "0.384",
"width": "0.108",
"height": "0.029"
},
"text": "sa"
}
]
},
{
"sentence": "Most baby lizards are green, yellow, or brown.",
"sentence_cn": "大多数幼年蜥蜴是绿色、黄色或棕色。",
"start": 59.71,
"end": 64.36,
"reason": null,
"group": [
{
"rect": {
"x": "0.088",
"y": "0.601",
"width": "0.683",
"height": "0.044"
},
"text": "Most baby lizards are"
},
{
"rect": {
"x": "0.087",
"y": "0.662",
"width": "0.744",
"height": "0.054"
},
"text": "green, yellow, or brown."
}
]
},
{
"sentence": "They can also be blue, red, or orange.",
"sentence_cn": "它们也可能是蓝色、红色或橙色。",
"start": 65.04,
"end": 69.17,
"reason": null,
"group": [
{
"rect": {
"x": "0.086",
"y": "0.733",
"width": "0.731",
"height": "0.049"
},
"text": "They can also be blue,"
},
{
"rect": {
"x": "0.084",
"y": "0.804",
"width": "0.468",
"height": "0.049"
},
"text": "red, or orange."
}
]
},
{
"sentence": "14",
"sentence_cn": "14",
"start": null,
"end": null,
"reason": "未找到匹配的音频片段,可能原因为非朗读内容(如页码或数字标记)",
"group": [
{
"rect": {
"x": "0.059",
"y": "0.919",
"width": "0.056",
"height": "0.035"
},
"text": "14"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0017_83a028f8e298c2370194efc29bf2828d@1080p.jpeg",
"page": "16",
"start": 71.04,
"end": 74.29,
"groups": [
{
"sentence": "o",
"sentence_cn": "o",
"start": null,
"end": null,
"reason": "文本内容为单个字母,可能是非朗读符号或错误内容,未在音频数据中找到匹配的时间信息",
"group": [
{
"rect": {
"x": "0.331",
"y": "0.188",
"width": "0.068",
"height": "0.039"
},
"text": "o"
}
]
},
{
"sentence": "All baby lizards have four legs.",
"sentence_cn": "所有小蜥蜴都有四条腿。",
"start": 71.04,
"end": 74.29,
"reason": null,
"group": [
{
"rect": {
"x": "0.123",
"y": "0.672",
"width": "0.699",
"height": "0.044"
},
"text": "All baby lizards have"
},
{
"rect": {
"x": "0.118",
"y": "0.736",
"width": "0.309",
"height": "0.052"
},
"text": "four legs."
}
]
},
{
"sentence": "15",
"sentence_cn": "15",
"start": null,
"end": null,
"reason": "文本内容为纯数字,可能是页码标注或非朗读内容,未在音频数据中找到匹配的时间信息",
"group": [
{
"rect": {
"x": "0.886",
"y": "0.916",
"width": "0.058",
"height": "0.038"
},
"text": "15"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0018_8de132cd02f5bcc720ddbccd2e876333@1080p.jpeg",
"page": "17",
"start": 75.95,
"end": 81.82,
"groups": [
{
"sentence": "Baby snakes start out small, but can grow to be really long!",
"sentence_cn": "小蛇刚开始很小,但可以长得非常长!",
"start": 75.95,
"end": 81.82,
"reason": null,
"group": [
{
"rect": {
"x": "0.091",
"y": "0.083",
"width": "0.751",
"height": "0.047"
},
"text": "Baby snakes start out"
},
{
"rect": {
"x": "0.091",
"y": "0.152",
"width": "0.529",
"height": "0.042"
},
"text": "small, but can "
},
{
"rect": {
"x": "0.607",
"y": "0.155",
"width": "0.255",
"height": "0.044"
},
"text": "grow to"
},
{
"rect": {
"x": "0.090",
"y": "0.219",
"width": "0.480",
"height": "0.047"
},
"text": "be really long!"
}
]
},
{
"sentence": "16",
"sentence_cn": "16",
"start": null,
"end": null,
"reason": "音频数据中未包含此句,可能原因:1.页码数字属于非朗读内容 2.音频文件被剪辑过 3.原始字幕数据不完整",
"group": [
{
"rect": {
"x": "0.058",
"y": "0.917",
"width": "0.056",
"height": "0.036"
},
"text": "16"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0019_a7560afdee111308452201960219296a@1080p.jpeg",
"page": "18",
"start": null,
"end": null,
"groups": []
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0020_473b9c57b8f81c9e4385335fc805068a@1080p.jpeg",
"page": "19",
"start": 83.65,
"end": 86.86,
"groups": [
{
"sentence": "e",
"sentence_cn": "e",
"start": null,
"end": null,
"reason": "音频数据中无对应文本内容,可能为标点符号、页码或未朗读的乱码字符",
"group": [
{
"rect": {
"x": "0.592",
"y": "0.286",
"width": "0.096",
"height": "0.047"
},
"text": "e"
}
]
},
{
"sentence": "Many baby snakes have scales.",
"sentence_cn": "许多小蛇有鳞片。",
"start": 83.65,
"end": 86.86,
"reason": null,
"group": [
{
"rect": {
"x": "0.103",
"y": "0.739",
"width": "0.597",
"height": "0.048"
},
"text": "Many baby snakes"
},
{
"rect": {
"x": "0.103",
"y": "0.808",
"width": "0.422",
"height": "0.039"
},
"text": "have scales."
}
]
},
{
"sentence": "18",
"sentence_cn": "18",
"start": null,
"end": null,
"reason": "音频数据中无对应文本内容,可能为未朗读的页码或数字标记",
"group": [
{
"rect": {
"x": "0.058",
"y": "0.915",
"width": "0.058",
"height": "0.040"
},
"text": "18"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0021_f7edd49a52d34a41f3229980361446a9@1080p.jpeg",
"page": "20",
"start": 88.58,
"end": 95.73,
"groups": [
{
"sentence": "Scales help baby snakes keep water in.",
"sentence_cn": "鳞片帮助幼蛇保持体内水分。",
"start": 88.58,
"end": 92.25,
"reason": null,
"group": [
{
"rect": {
"x": "0.134",
"y": "0.292",
"width": "0.572",
"height": "0.044"
},
"text": "Scales help baby"
},
{
"rect": {
"x": "0.132",
"y": "0.361",
"width": "0.732",
"height": "0.043"
},
"text": "snakes keep water in."
}
]
},
{
"sentence": "They also help them to move around.",
"sentence_cn": "它们也帮助幼蛇四处移动。",
"start": 92.97,
"end": 95.73,
"reason": null,
"group": [
{
"rect": {
"x": "0.134",
"y": "0.429",
"width": "0.687",
"height": "0.042"
},
"text": "They also help them"
},
{
"rect": {
"x": "0.131",
"y": "0.498",
"width": "0.557",
"height": "0.034"
},
"text": "to move around."
}
]
},
{
"sentence": "19",
"sentence_cn": "19",
"start": null,
"end": null,
"reason": "音���数据中缺少对应文本内容,可能为页码/非朗读内容/乱码",
"group": [
{
"rect": {
"x": "0.884",
"y": "0.917",
"width": "0.057",
"height": "0.037"
},
"text": "19"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0022_0f2b0cc2018e917204cbd59cc141484b@1080p.jpeg",
"page": "21",
"start": 97.59,
"end": 101.28,
"groups": [
{
"sentence": "All baby snakes say, hiss!",
"sentence_cn": "所有的小蛇都会发出嘶嘶声!",
"start": 97.59,
"end": 101.28,
"reason": null,
"group": [
{
"rect": {
"x": "0.165",
"y": "0.374",
"width": "0.526",
"height": "0.045"
},
"text": "All baby snakes"
},
{
"rect": {
"x": "0.162",
"y": "0.442",
"width": "0.303",
"height": "0.045"
},
"text": "say, hiss!"
}
]
},
{
"sentence": "20",
"sentence_cn": "20",
"start": null,
"end": null,
"reason": "音频数据中未找到该句对应的内容,可能原因为:1.该句为页码或非朗读内容;2.音频预处理时被识别为乱码或非内容元素被过滤",
"group": [
{
"rect": {
"x": "0.056",
"y": "0.919",
"width": "0.065",
"height": "0.035"
},
"text": "20"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0023_f997ec9433e18a4141f5f3b6baa63dc2@1080p.jpeg",
"page": "22",
"start": null,
"end": null,
"groups": []
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0024_091aa527136dbdcbfbccd7693ad88862@1080p.jpeg",
"page": "23",
"start": null,
"end": null,
"groups": []
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0025_2701a568543432a44b7211b2b4476f78@1080p.jpeg",
"page": "24",
"start": null,
"end": null,
"groups": []
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0026_01af8d1e9303a70cd78f4108766e8eb7@1080p.jpeg",
"page": "25",
"start": null,
"end": null,
"groups": []
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0027_4db89af97bf7aab0cb4116a4364033eb@1080p.jpeg",
"page": "26",
"start": null,
"end": null,
"groups": []
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0028_fce2597fd32eb582ffe7cb8c76314189@1080p.jpeg",
"page": "27",
"start": null,
"end": null,
"groups": []
}
]
}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
html, body {
height: 100%;
* {
margin: 0;
padding: 0;
background: #fff;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
overflow: hidden;
box-sizing: border-box;
}
body {
min-height: 100vh;
min-width: 100vw;
box-sizing: border-box;
font-family: Arial, sans-serif;
background-color: #f5f5f5;
overflow: hidden;
}
#app {
width: 100vw;
height: 100vh;
position: relative;
overflow: hidden;
background-color: #000;
}
.page-container {
width: 100vw;
height: 100vh;
.book-container {
width: 100%;
height: 100%;
position: relative;
overflow: hidden;
}
.full-image-wrapper {
width: 100vw;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: #fff;
position: absolute;
top: 0;
left: 0;
}
.full-image {
max-width: 100vw;
max-height: 100vh;
width: auto;
height: auto;
display: block;
margin: auto;
.page-image {
max-width: 100%;
max-height: 100%;
object-fit: contain;
background: #fff;
border-radius: 0;
box-shadow: none;
}
.rect-layer {
position: absolute;
border: 3px dashed #2196f3;
box-sizing: border-box;
pointer-events: none;
border-radius: 4px;
z-index: 2;
/* background: rgba(33,150,243,0.15); */
/* opacity: 0; */
/* transform: scale(0.95); */
/* transition: opacity 0.3s ease, transform 0.3s ease; */
display: block;
}
.rect-layer.rect-visible {
opacity: 1;
transform: scale(1);
.image-container {
position: relative;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
/* 单词级别矩形高亮样式 */
.word-rect-layer {
.highlight-rect {
position: absolute;
background-color: rgba(255, 235, 59, 0.3);
border: 2px solid #ffeb3b;
border-radius: 4px;
border: 2px dashed #007bff;
background-color: transparent;
pointer-events: none;
z-index: 3;
box-shadow: 0 0 8px rgba(255, 235, 59, 0.5);
}
.word-rect-layer:hover {
background-color: rgba(255, 235, 59, 0.5);
box-shadow: 0 0 12px rgba(255, 235, 59, 0.8);
z-index: 15;
transition: all 0.2s ease;
}
.subtitle-bar {
position: fixed;
left: 50%;
bottom: 40px;
transform: translateX(-50%);
z-index: 20;
.word-highlight {
position: absolute;
background-color: rgba(255, 235, 59, 0.2);
border: 1px solid #f57f17;
border-radius: 3px;
pointer-events: none;
padding: 10px 20px;
background: rgba(0, 0, 0, 0.2);
border-radius: 4px;
width: 80%;
}
.fixed-btn-group {
position: fixed;
left: 32px;
bottom: 32px;
z-index: 30;
display: flex;
gap: 12px;
align-items: center;
}
.fixed-btn-group .el-button {
border-radius: 50px;
box-shadow: 0 2px 8px rgba(0,0,0,0.12);
padding: 12px 24px;
font-size: 18px;
}
/* 翻页动画 */
.slide-left-enter-active,
.slide-left-leave-active,
.slide-right-enter-active,
.slide-right-leave-active {
transition: all 0.5s ease;
}
.slide-left-enter {
transform: translateX(100%);
opacity: 0;
}
.slide-left-leave-to {
transform: translateX(-100%);
opacity: 0;
}
.slide-right-enter {
transform: translateX(-100%);
opacity: 0;
}
.slide-right-leave-to {
transform: translateX(100%);
opacity: 0;
}
/* 隐藏滚动条 */
body::-webkit-scrollbar, html::-webkit-scrollbar {
display: none;
}
/* 页数提示样式,可后续隐藏 */
#app > div[style*="color:red"] {
margin-bottom: 8px;
}
#test{
margin: 80px;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.content-wrapper {
display: flex;
flex-direction: column;
gap: 20px;
margin-bottom: 20px;
z-index: 1;
transition: all 0.2s ease;
box-shadow: 0 0 5px rgba(255, 235, 59, 0.5);
}
.image-container {
position: relative;
width: 100%;
background: #f5f5f5;
border-radius: 8px;
overflow: hidden;
}
.image-container img {
width: 100%;
height: auto;
display: block;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.highlight-rect {
.controls {
position: absolute;
border: 2px solid #409EFF;
background-color: rgba(64, 158, 255, 0.1);
pointer-events: none;
transition: all 0.3s ease;
bottom: 20px;
left: 20px;
z-index: 100;
display: flex;
gap: 10px;
}
.subtitle-container {
min-height: 60px;
padding: 15px;
background: #fff;
border-radius: 8px;
box-shadow: 0 2px 12px 0 rgba(0,0,0,0.1);
.control-btn {
width: 50px;
height: 50px;
border: none;
border-radius: 50%;
background-color: rgba(255, 255, 255, 0.9);
color: #333;
font-size: 18px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.3s ease;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.subtitle-text {
color: #fff;
font-size: 2.4rem;
font-weight: bold;
text-align: center;
line-height: 1.5;
.control-btn:hover {
background-color: rgba(255, 255, 255, 1);
transform: scale(1.1);
}
.subtitle-text span {
display: inline-block;
margin: 0 8px;
transition: all 0.2s ease;
.control-btn:active {
transform: scale(0.95);
}
.subtitle-text .highlighted-word {
color: #ffeb3b;
text-shadow: 0 0 10px rgba(255, 235, 59, 0.8);
transform: scale(1.05);
font-weight: 900;
animation: wordPulse 0.5s ease-in-out;
.control-btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}
@keyframes wordPulse {
0% { transform: scale(1); }
50% { transform: scale(1.1); }
100% { transform: scale(1.05); }
.play-btn {
background-color: rgba(76, 175, 80, 0.9);
color: white;
}
.controls {
display: flex;
justify-content: center;
gap: 20px;
padding: 20px 0;
.play-btn:hover {
background-color: rgba(76, 175, 80, 1);
}
.controls .el-button {
min-width: 100px;
.pause-btn {
background-color: rgba(255, 152, 0, 0.9);
color: white;
}
@media (max-width: 768px) {
.container {
padding: 10px;
}
.controls {
flex-direction: column;
align-items: center;
}
.controls .el-button {
width: 100%;
max-width: 300px;
}
.pause-btn:hover {
background-color: rgba(255, 152, 0, 1);
}
/* 调试面板样式 */
.debug-panel {
position: fixed;
.page-info {
position: absolute;
top: 20px;
right: 20px;
background: rgba(0, 0, 0, 0.8);
color: #fff;
padding: 15px;
border-radius: 8px;
background-color: rgba(0, 0, 0, 0.7);
color: white;
padding: 10px 15px;
border-radius: 5px;
font-size: 14px;
z-index: 100;
min-width: 200px;
}
.debug-info div {
margin-bottom: 5px;
font-family: monospace;
}
/* 预加载界面样式 */
.loading-screen {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
display: flex;
align-items: center;
justify-content: center;
z-index: 9999;
}
.loading-content {
text-align: center;
.loading {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: white;
max-width: 400px;
padding: 40px;
}
.loading-spinner {
width: 60px;
height: 60px;
border: 4px solid rgba(255, 255, 255, 0.3);
border-top: 4px solid white;
border-radius: 50%;
animation: spin 1s linear infinite;
margin: 0 auto 20px;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.loading-text {
font-size: 24px;
font-weight: bold;
margin-bottom: 30px;
}
.loading-progress {
margin-top: 20px;
}
.progress-bar {
width: 100%;
height: 8px;
background: rgba(255, 255, 255, 0.3);
border-radius: 4px;
overflow: hidden;
margin-bottom: 10px;
}
.progress-fill {
height: 100%;
background: white;
border-radius: 4px;
transition: width 0.3s ease;
font-size: 18px;
z-index: 200;
}
.progress-text {
font-size: 16px;
opacity: 0.8;
.error {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: #ff4444;
font-size: 18px;
text-align: center;
z-index: 200;
}
/* 主要内容样式 */
.main-content {
width: 100vw;
height: 100vh;
position: relative;
overflow: hidden;
}
\ No newline at end of file
......@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Book Player</title>
<title>绘本阅读器</title>
<link href="./index.css" rel="stylesheet" >
<script type="text/javascript" src="//teach.cdn.ireadabc.com/h5template/h5-static-lib/js/jquery-1.12.3.min.js"></script>
<script type="text/javascript" src="//teach.cdn.ireadabc.com/h5template/h5-static-lib/js/air.js"></script>
......@@ -16,72 +16,82 @@
</head>
<body>
<div id="app">
<!-- 预加载界面 -->
<div class="loading-screen" v-if="isLoading">
<div class="loading-content">
<div class="loading-spinner"></div>
<div class="loading-text">正在加载资源...</div>
<div class="loading-progress">
<div class="progress-bar">
<div class="progress-fill" :style="{ width: loadingProgress + '%' }"></div>
</div>
<div class="progress-text">{{ loadedAssets }}/{{ totalAssets }} ({{ loadingProgress }}%)</div>
</div>
</div>
<div v-if="loading" class="loading">
加载中...
</div>
<!-- 主要内容 -->
<div class="main-content" v-else>
<div class="page-container">
<div class="full-image-wrapper" :key="currentPage">
<img ref="mainImg" :src="pages[currentPage].image_url" :alt="'Page ' + pages[currentPage].page" v-if="pages.length" class="full-image"/>
<template v-if="currentRects && isRectVisible">
<div v-for="(rect, idx) in currentRects" :key="idx" class="rect-layer rect-visible" :style="getRectStyle(rect)"></div>
</template>
<!-- 单词级别矩形高亮 -->
<template v-if="highlightedWordRects && isRectVisible">
<div
v-for="(wordRect, idx) in highlightedWordRects"
:key="'word-' + idx"
class="word-rect-layer"
:style="getWordRectStyle(wordRect)"
:title="wordRect.text"
></div>
</template>
</div>
</div>
<div class="subtitle-bar" v-if="currentAudioText">
<div class="subtitle-text">
<span
v-for="(word, index) in currentWords"
:key="index"
:class="{ 'highlighted-word': highlightedWordIndexes.includes(index) }"
>
{{ word.word }}
</span>
</div>
</div>
<div v-else-if="error" class="error">
{{ error }}
</div>
<div v-else class="book-container">
<!-- 调试面板 -->
<div class="debug-panel" v-if="isPlaying">
<div class="debug-info">
<div>时间: {{ debugInfo.currentTime.toFixed(2) }}s</div>
<div>单词数: {{ debugInfo.totalWords }}</div>
<div>高亮索引: {{ debugInfo.highlightedIndexes.join(', ') }}</div>
<div>当前单词: {{ debugInfo.currentWord }}</div>
<div>单词矩形数: {{ debugInfo.wordRectsCount }}</div>
<div>组单词数: {{ debugInfo.groupWordsCount }}</div>
</div>
<!-- 图片容器 -->
<div class="image-container">
<img
v-if="currentPage"
:src="currentPage.image_url"
:alt="'第' + (currentPageIndex + 1) + '页'"
class="page-image"
@load="onImageLoad"
@error="onImageError"
/>
<!-- 蓝色矩形框 -->
<div
v-for="(rect, index) in activeRects"
:key="'rect-' + index"
class="highlight-rect"
:style="getRectStyle(rect)"
></div>
<!-- 单词高亮 -->
<div
v-for="(word, index) in activeWords"
:key="'word-' + index"
class="word-highlight"
:style="getWordStyle(word)"
></div>
</div>
<div class="fixed-btn-group">
<el-button
type="primary"
:icon="isPlaying ? 'el-icon-video-pause' : 'el-icon-video-play'"
@click="togglePlay">
{{ isPlaying ? '暂停' : '播放' }}
</el-button>
<el-button icon="el-icon-arrow-left" @click="prevPage">上一页</el-button>
<el-button icon="el-icon-arrow-right" @click="nextPage">下一页</el-button>
<!-- 控制按钮 -->
<div class="controls">
<button
class="control-btn"
:disabled="currentPageIndex === 0"
@click="previousPage"
title="上一页"
>
‹
</button>
<button
v-if="!isPlaying"
class="control-btn play-btn"
@click="playAudio"
title="播放"
>
▶
</button>
<button
v-else
class="control-btn pause-btn"
@click="pauseAudio"
title="暂停"
>
❚❚
</button>
<button
class="control-btn"
:disabled="currentPageIndex === totalPages - 1"
@click="nextPage"
title="下一页"
>
›
</button>
</div>
</div>
</div>
......
......@@ -19,494 +19,372 @@ $(function() {
});
function initializeApp(data) {
console.log('Vue 初始化', data);
new Vue({
el: '#app',
data: {
// 数据相关
bookData: data,
pages: data.pages || [],
audioUrl: data.audio_points?.audio_url || '',
audioPoints: data.audio_points?.points || [],
currentPage: 0,
audioUrl: data.audio_url,
// 状态相关
loading: false,
error: null,
isPlaying: false,
currentPageIndex: 0,
// 音频相关
audio: null,
currentTime: 0,
activeGroupIndexes: [],
imageSize: { width: 0, height: 0 },
currentAudioPointIndex: -1,
isManualPageChange: false,
currentAudioText: '',
isRectVisible: false,
pageTransition: 'slide-left',
needJumpToPageStartOnPlay: false,
// 逐字高亮相关
currentWords: [],
highlightedWordIndexes: [],
// 单词级别矩形高亮相关
currentGroupWords: [], // 当前活跃组的单词矩形信息
highlightedWordRects: [], // 当前高亮的单词矩形
// 预加载相关
isLoading: true,
loadingProgress: 0,
totalAssets: 0,
loadedAssets: 0,
// 图片相关
imageWidth: 0,
imageHeight: 0,
imageLoaded: false,
// 高亮相关
activeRects: [],
activeWords: [],
// 定时器
audioTimer: null,
highlightTimer: null
},
computed: {
currentGroups() {
if (!this.pages.length) return [];
return this.pages[this.currentPage]?.groups || [];
totalPages() {
return this.pages.length;
},
currentRects() {
const rects = [];
this.activeGroupIndexes.forEach(groupIndex => {
const group = this.currentGroups[groupIndex];
if (group && Array.isArray(group.group)) {
group.group.forEach(item => {
if (item.rect) {
rects.push(item.rect);
}
});
}
});
return rects;
},
currentGroup() {
if (this.currentGroupIndex === -1) return null;
return this.currentGroups[this.currentGroupIndex] || null;
currentPage() {
return this.pages[this.currentPageIndex] || null;
},
currentRectStyle() {
if (!this.currentRect || !this.imageSize.width || !this.imageSize.height) {
return {};
}
const r = this.currentRect;
return {
left: (r.x * this.imageSize.width) + 'px',
top: (r.y * this.imageSize.height) + 'px',
width: (r.width * this.imageSize.width) + 'px',
height: (r.height * this.imageSize.height) + 'px',
};
currentPageStartTime() {
return this.currentPage ? this.currentPage.start : 0;
},
// 调试信息
debugInfo() {
if (this.currentWords.length === 0) return '无单词数据';
const currentWord = this.highlightedWordIndexes.length > 0 ? this.currentWords[this.highlightedWordIndexes[0]] : null;
return {
currentTime: this.audio ? this.audio.currentTime : 0,
totalWords: this.currentWords.length,
highlightedIndexes: this.highlightedWordIndexes,
currentWord: currentWord ? `${currentWord.word} (${currentWord.start}-${currentWord.end})` : '无',
wordRectsCount: this.highlightedWordRects.length,
groupWordsCount: this.currentGroupWords.length
};
}
},
watch: {
currentPage(newVal, oldVal) {
this.currentGroupIndex = -1;
this.updateImageSize();
// 设置翻页动画方向
this.pageTransition = newVal > oldVal ? 'slide-left' : 'slide-right';
if (this.isManualPageChange && this.isPlaying) {
// 正在播放时,翻页立即跳到新页开始时间
this.audio.currentTime = this.pages[this.currentPage].start;
}
// 如果音频暂停,翻页后下次播放要跳到新页开始时间
if (this.isManualPageChange && !this.isPlaying) {
this.needJumpToPageStartOnPlay = true;
}
// 翻页后自动跳到新页面第一个有时间戳的group
const groups = this.pages[this.currentPage]?.groups || [];
let found = false;
for (let i = 0; i < groups.length; i++) {
if (groups[i].start != null && groups[i].end != null) {
this.currentGroupIndex = i;
found = true;
break;
}
}
if (!found) this.currentGroupIndex = -1;
this.isManualPageChange = false;
currentPageEndTime() {
return this.currentPage ? this.currentPage.end : 0;
}
},
mounted() {
this.audio = new Audio(this.audioUrl);
this.audio.addEventListener('timeupdate', this.handleTimeUpdate);
this.audio.addEventListener('ended', this.handleAudioEnded);
this.updateImageSize();
window.addEventListener('resize', this.updateImageSize);
// 监听图片加载完成,确保能拿到尺寸
this.$nextTick(() => {
const img = this.$refs.mainImg;
if (img) {
img.onload = () => {
this.updateImageSize();
};
}
});
// 开始预加载
this.startPreloading();
console.log('Vue组件已挂载,数据:', this.bookData);
this.initAudio();
this.loadCurrentPage();
// 监听窗口大小变化,重新计算高亮位置
window.addEventListener('resize', this.onWindowResize);
},
beforeDestroy() {
if (this.audio) {
this.audio.removeEventListener('timeupdate', this.handleTimeUpdate);
this.audio.removeEventListener('ended', this.handleAudioEnded);
this.audio.pause();
}
window.removeEventListener('resize', this.updateImageSize);
this.cleanup();
window.removeEventListener('resize', this.onWindowResize);
},
methods: {
updateImageSize() {
this.$nextTick(() => {
var img = this.$refs.mainImg;
if (img && img.naturalWidth) {
this.imageSize = {
width: img.clientWidth,
height: img.clientHeight
};
}
// 初始化音频
initAudio() {
if (!this.audioUrl) {
this.error = '音频文件地址无效';
return;
}
console.log('初始化音频:', this.audioUrl);
this.audio = new Audio(this.audioUrl);
this.audio.preload = 'auto';
this.audio.addEventListener('loadeddata', () => {
console.log('音频加载完成');
});
this.audio.addEventListener('error', (e) => {
console.error('音频加载失败:', e);
this.error = '音频加载失败';
});
this.audio.addEventListener('ended', () => {
this.onAudioEnded();
});
this.audio.addEventListener('timeupdate', () => {
this.onAudioTimeUpdate();
});
},
handleTimeUpdate() {
// 音频时间更新
onAudioTimeUpdate() {
if (!this.audio) return;
this.currentTime = this.audio.currentTime;
this.updateHighlights();
this.updatePageByTime();
// 每5秒输出一次调试信息
if (Math.floor(this.currentTime) % 5 === 0 && this.currentTime > 0) {
console.log('当前时间:', this.currentTime, '当前页面:', this.currentPageIndex);
}
},
// 音频结束
onAudioEnded() {
this.isPlaying = false;
this.currentPageIndex = 0;
this.currentTime = 0;
this.audio.currentTime = 0;
this.clearHighlights();
this.loadCurrentPage();
},
// 根据时间更新页面
updatePageByTime() {
if (!this.audio || !this.pages.length) return;
const currentTime = this.audio.currentTime;
// 检查是否需要切换页面
// 找到当前时间对应的页面
for (let i = 0; i < this.pages.length; i++) {
const page = this.pages[i];
if (currentTime >= page.start && currentTime <= page.end) {
if (this.currentPage !== i) {
this.currentPage = i;
if (this.currentPageIndex !== i) {
console.log('切换到页面:', i, '时间:', currentTime);
this.currentPageIndex = i;
this.loadCurrentPage();
}
break;
}
}
},
// 更新高亮
updateHighlights() {
if (!this.currentPage || !this.imageLoaded) return;
// 更新当前页面的高亮 groups
const currentPage = this.pages[this.currentPage];
if (currentPage && currentPage.groups) {
// 重置活跃组索引数组
this.activeGroupIndexes = [];
this.currentGroupWords = [];
this.highlightedWordRects = [];
// 遍历所有组,找出所有时间匹配的组
currentPage.groups.forEach((group, idx) => {
if (group.start != null && group.end != null &&
currentTime >= group.start && currentTime <= group.end) {
// 将匹配的组索引添加到活跃组数组中
this.activeGroupIndexes.push(idx);
// 处理单词级别的矩形高亮
if (group.group && Array.isArray(group.group)) {
group.group.forEach(item => {
if (item.words && Array.isArray(item.words)) {
// 将单词信息添加到当前组单词列表
item.words.forEach(word => {
this.currentGroupWords.push({
...word,
groupIndex: idx,
itemIndex: group.group.indexOf(item)
});
});
// 只高亮当前正在播放的单词
if (this.currentWords.length > 0 && this.highlightedWordIndexes.length > 0) {
this.highlightedWordIndexes.forEach(hIdx => {
const audioWord = this.currentWords[hIdx];
// 收集所有匹配的页面单词
const matchingWords = [];
item.words.forEach((word, wordIdx) => {
if (
audioWord &&
word.text &&
audioWord.word &&
word.text.trim().toLowerCase().replace(/[^\w\s]/g, '') === audioWord.word.trim().toLowerCase().replace(/[^\w\s]/g, '')
) {
matchingWords.push({
...word,
groupIndex: idx,
itemIndex: group.group.indexOf(item),
audioWord,
wordIdx
});
}
});
// 根据音频单词的索引选择对应的页面单词
if (matchingWords.length > 0) {
// 如果匹配的单词数量大于音频索引,选择对应位置的单词
// 否则选择最后一个匹配的单词
const selectedWord = matchingWords[hIdx] || matchingWords[matchingWords.length - 1];
this.highlightedWordRects.push(selectedWord);
}
});
}
}
});
}
}
});
// 如果有任何匹配的组,设置为可见
this.isRectVisible = this.activeGroupIndexes.length > 0;
}
// 字幕严格跟随 audio_points.points
let subtitle = '';
let currentPointIndex = -1;
let currentWords = [];
let highlightedWordIndexes = [];
const currentTime = this.audio.currentTime;
const newRects = [];
const newWords = [];
for (let i = 0; i < this.audioPoints.length; i++) {
const p = this.audioPoints[i];
if (currentTime >= p.start && currentTime <= p.end) {
subtitle = p.text;
currentPointIndex = i;
currentWords = p.words || [];
// 改进的单词高亮逻辑
if (currentWords.length > 0) {
// 找到所有时间匹配的单词(允许多个单词同时高亮)
for (let j = 0; j < currentWords.length; j++) {
const word = currentWords[j];
if (currentTime >= word.start && currentTime <= word.end) {
highlightedWordIndexes.push(j);
// 检查是否在当前页的时间范围内
if (currentTime >= this.currentPage.start && currentTime <= this.currentPage.end) {
// 遍历当前页面的所有组
this.currentPage.groups.forEach(group => {
// 检查句子时间
if (currentTime >= group.start && currentTime <= group.end) {
// 遍历句子中的文本组
group.group.forEach(textGroup => {
// 添加文本组的矩形框
if (textGroup.rect) {
newRects.push(textGroup.rect);
}
}
// 如果没有精确匹配,尝试找到所有在合理时间范围内的单词
if (highlightedWordIndexes.length === 0) {
for (let j = 0; j < currentWords.length; j++) {
const word = currentWords[j];
const distanceToStart = Math.abs(currentTime - word.start);
const distanceToEnd = Math.abs(currentTime - word.end);
const minWordDistance = Math.min(distanceToStart, distanceToEnd);
// 如果距离在合理范围内(比如0.3秒内),就高亮这个单词
if (minWordDistance <= 0.3) {
highlightedWordIndexes.push(j);
}
// 检查单词时间 - 单词高亮应该保持到切换页面
if (textGroup.words) {
textGroup.words.forEach(word => {
if (word.start !== null && word.end !== null) {
// 如果当前时间已经过了这个单词的开始时间,就保持高亮直到切换页面
if (currentTime >= word.start) {
newWords.push(word);
}
}
});
}
}
// 调试信息
const highlightedWords = highlightedWordIndexes.map(idx => currentWords[idx]?.word).join(', ');
console.log('当前时间:', currentTime, '高亮单词索引:', highlightedWordIndexes, '单词:', highlightedWords);
});
}
break;
}
});
}
this.currentAudioText = subtitle;
this.currentAudioPointIndex = currentPointIndex;
this.currentWords = currentWords;
this.highlightedWordIndexes = highlightedWordIndexes;
},
handleAudioEnded() {
this.isPlaying = false;
this.currentAudioText = '';
this.isRectVisible = false;
this.activeGroupIndexes = [];
this.currentPage = 0; // 播放结束后回到第一页
// 重置逐字高亮状态
this.currentWords = [];
this.highlightedWordIndexes = [];
this.currentAudioPointIndex = -1;
// 重置单词矩形高亮状态
this.currentGroupWords = [];
this.highlightedWordRects = [];
},
togglePlay() {
if (this.isPlaying) {
this.audio.pause();
this.isPlaying = false;
} else {
// 判断当前时间是否在当前页范围内
const page = this.pages[this.currentPage];
if (
this.needJumpToPageStartOnPlay ||
this.audio.currentTime < page.start ||
this.audio.currentTime > page.end ||
this.audio.currentTime === 0 ||
this.audio.ended
) {
this.audio.currentTime = page.start;
}
this.needJumpToPageStartOnPlay = false;
this.audio.play();
this.isPlaying = true;
// 只在有变化时更新,避免不必要的DOM操作
if (JSON.stringify(this.activeRects) !== JSON.stringify(newRects) ||
JSON.stringify(this.activeWords) !== JSON.stringify(newWords)) {
this.activeRects = newRects;
this.activeWords = newWords;
console.log('更新高亮:', newRects.length, '个矩形框,', newWords.length, '个单词');
}
},
prevPage() {
let nextPage = this.currentPage - 1;
while (nextPage >= 0) {
const page = this.pages[nextPage];
if (page.start != null && page.end != null) break;
nextPage--;
}
if (nextPage >= 0) {
this.isManualPageChange = true;
this.currentPage = nextPage;
}
// 清除高亮
clearHighlights() {
this.activeRects = [];
this.activeWords = [];
},
nextPage() {
let nextPage = this.currentPage + 1;
while (nextPage < this.pages.length) {
const page = this.pages[nextPage];
if (page.start != null && page.end != null) break;
nextPage++;
}
if (nextPage < this.pages.length) {
this.isManualPageChange = true;
this.currentPage = nextPage;
}
// 加载当前页面
loadCurrentPage() {
console.log('加载页面:', this.currentPageIndex, this.currentPage);
this.clearHighlights();
this.imageLoaded = false;
},
getRectStyle(rect) {
if (!rect || !this.imageSize.width || !this.imageSize.height) return {};
// 获取图片元素
const img = this.$refs.mainImg;
if (!img) return {};
// 获取图片的实际显示尺寸和位置
const imgRect = img.getBoundingClientRect();
// 计算矩形的实际位置和大小
const x = parseFloat(rect.x);
const y = parseFloat(rect.y);
const width = parseFloat(rect.width);
const height = parseFloat(rect.height);
// 图片加载完成
onImageLoad(event) {
const img = event.target;
this.imageWidth = img.naturalWidth;
this.imageHeight = img.naturalHeight;
this.imageLoaded = true;
console.log('图片加载完成:', this.imageWidth, this.imageHeight);
// 计算实际像素位置
return {
position: 'absolute',
left: (x * imgRect.width + imgRect.left) + 'px',
top: (y * imgRect.height + imgRect.top) + 'px',
width: (width * imgRect.width) + 'px',
height: (height * imgRect.height) + 'px',
display: rect.visible === false ? 'none' : 'block'
};
// 如果音频正在播放,立即更新高亮
if (this.isPlaying) {
this.updateHighlights();
}
},
getWordRectStyle(wordRect) {
if (!wordRect || !wordRect.rect || !this.imageSize.width || !this.imageSize.height) return {};
// 获取图片元素
const img = this.$refs.mainImg;
if (!img) return {};
// 获取图片的实际显示尺寸和位置
const imgRect = img.getBoundingClientRect();
const x = parseFloat(wordRect.rect.x);
const y = parseFloat(wordRect.rect.y);
const width = parseFloat(wordRect.rect.width);
const height = parseFloat(wordRect.rect.height);
return {
position: 'absolute',
left: (x * imgRect.width + imgRect.left) + 'px',
top: (y * imgRect.height + imgRect.top) + 'px',
width: (width * imgRect.width) + 'px',
height: (height * imgRect.height) + 'px',
backgroundColor: 'rgba(255, 235, 59, 0.3)',
border: '2px solid #ffeb3b',
borderRadius: '4px',
pointerEvents: 'none',
zIndex: 3
};
// 图片加载失败
onImageError() {
this.error = '图片加载失败';
},
startPreloading() {
const assetsToLoad = [];
// 获取矩形框样式
getRectStyle(rect) {
if (!this.imageLoaded || !rect) return {};
// 添加所有图片
if (Array.isArray(this.pages)) {
this.pages.forEach(page => {
if (page.image_url) {
assetsToLoad.push({
type: 'image',
url: page.image_url,
name: `Page ${page.page || 'unknown'}`
});
}
});
try {
const imgElement = document.querySelector('.page-image');
if (!imgElement) return {};
const imgRect = imgElement.getBoundingClientRect();
const containerRect = imgElement.parentElement.getBoundingClientRect();
// 计算图片在容器中的实际位置和尺寸
const imgLeft = imgRect.left - containerRect.left;
const imgTop = imgRect.top - containerRect.top;
const imgWidth = imgRect.width;
const imgHeight = imgRect.height;
// 根据相对坐标计算绝对位置
const left = imgLeft + parseFloat(rect.x) * imgWidth;
const top = imgTop + parseFloat(rect.y) * imgHeight;
const width = parseFloat(rect.width) * imgWidth;
const height = parseFloat(rect.height) * imgHeight;
return {
position: 'absolute',
left: left + 'px',
top: top + 'px',
width: width + 'px',
height: height + 'px'
};
} catch (error) {
console.error('矩形框样式计算错误:', error);
return {};
}
},
// 获取单词高亮样式
getWordStyle(word) {
if (!this.imageLoaded || !word || !word.rect) return {};
// 添加音频
if (this.audioUrl) {
assetsToLoad.push({
type: 'audio',
url: this.audioUrl,
name: 'Audio'
});
try {
const imgElement = document.querySelector('.page-image');
if (!imgElement) return {};
const imgRect = imgElement.getBoundingClientRect();
const containerRect = imgElement.parentElement.getBoundingClientRect();
// 计算图片在容器中的实际位置和尺寸
const imgLeft = imgRect.left - containerRect.left;
const imgTop = imgRect.top - containerRect.top;
const imgWidth = imgRect.width;
const imgHeight = imgRect.height;
// 根据相对坐标计算绝对位置
const left = imgLeft + parseFloat(word.rect.x) * imgWidth;
const top = imgTop + parseFloat(word.rect.y) * imgHeight;
const width = parseFloat(word.rect.width) * imgWidth;
const height = parseFloat(word.rect.height) * imgHeight;
return {
position: 'absolute',
left: left + 'px',
top: top + 'px',
width: width + 'px',
height: height + 'px'
};
} catch (error) {
console.error('单词样式计算错误:', error);
return {};
}
},
// 播放音频
playAudio() {
if (!this.audio) return;
this.totalAssets = assetsToLoad.length;
this.loadedAssets = 0;
// 如果音频暂停在当前页面,继续播放
if (this.isPlaying) return;
if (this.totalAssets === 0) {
// 没有需要预加载的资源,直接完成
this.finishPreloading();
return;
// 如果音频不在当前页面时间范围内,跳转到当前页面开始时间
if (this.currentTime < this.currentPageStartTime || this.currentTime > this.currentPageEndTime) {
console.log('跳转到页面开始时间:', this.currentPageStartTime);
this.audio.currentTime = this.currentPageStartTime;
}
// 开始加载每个资源
assetsToLoad.forEach(asset => {
if (asset.type === 'image') {
this.loadImage(asset);
} else if (asset.type === 'audio') {
this.loadAudio(asset);
}
this.audio.play().then(() => {
this.isPlaying = true;
console.log('开始播放音频');
}).catch(error => {
console.error('播放失败:', error);
this.error = '播放失败';
});
},
loadImage(asset) {
const img = new Image();
img.onload = () => {
this.assetLoaded(asset);
};
img.onerror = () => {
console.warn(`Failed to load image: ${asset.url}`);
this.assetLoaded(asset);
};
img.src = asset.url;
// 暂停音频
pauseAudio() {
if (!this.audio) return;
this.audio.pause();
this.isPlaying = false;
},
loadAudio(asset) {
const audio = new Audio();
audio.oncanplaythrough = () => {
this.assetLoaded(asset);
};
audio.onerror = () => {
console.warn(`Failed to load audio: ${asset.url}`);
this.assetLoaded(asset);
};
audio.src = asset.url;
// 上一页
previousPage() {
if (this.currentPageIndex > 0) {
this.currentPageIndex--;
this.loadCurrentPage();
// 如果音频正在播放,跳转到新页面的开始时间
if (this.isPlaying) {
this.audio.currentTime = this.currentPageStartTime;
}
}
},
assetLoaded(asset) {
this.loadedAssets++;
this.loadingProgress = Math.round((this.loadedAssets / this.totalAssets) * 100);
console.log(`Loaded ${asset.type}: ${asset.name} (${this.loadedAssets}/${this.totalAssets})`);
if (this.loadedAssets >= this.totalAssets) {
this.finishPreloading();
// 下一页
nextPage() {
if (this.currentPageIndex < this.totalPages - 1) {
this.currentPageIndex++;
this.loadCurrentPage();
// 如果音频正在播放,跳转到新页面的开始时间
if (this.isPlaying) {
this.audio.currentTime = this.currentPageStartTime;
}
}
},
finishPreloading() {
console.log('All assets preloaded successfully!');
this.isLoading = false;
// 窗口大小变化处理
onWindowResize() {
// 强制重新计算高亮位置
this.$forceUpdate();
},
// 清理资源
cleanup() {
if (this.audio) {
this.audio.pause();
this.audio = null;
}
// 初始化音频播放器
this.audio = new Audio(this.audioUrl);
this.audio.addEventListener('timeupdate', this.handleTimeUpdate);
this.audio.addEventListener('ended', this.handleAudioEnded);
this.updateImageSize();
window.addEventListener('resize', this.updateImageSize);
if (this.audioTimer) {
clearInterval(this.audioTimer);
this.audioTimer = null;
}
// 监听图片加载完成,确保能拿到尺寸
this.$nextTick(() => {
const img = this.$refs.mainImg;
if (img) {
img.onload = () => {
this.updateImageSize();
};
}
});
if (this.highlightTimer) {
clearInterval(this.highlightTimer);
this.highlightTimer = null;
}
}
}
});
......
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "教育内容数据结构",
"description": "包含音频和页面数据的教育内容 JSON Schema",
"type": "object",
"properties": {
"audio_url": {
"type": "string",
"format": "uri",
"description": "音频文件的 URL 地址"
},
"pages": {
"type": "array",
"description": "页面数据数组",
"items": {
"type": "object",
"properties": {
"image_url": {
"type": "string",
"format": "uri",
"description": "页面图片的 URL 地址"
},
"page": {
"type": "integer",
"description": "页面编号"
},
"start": {
"type": "number",
"description": "页面开始时间(秒)"
},
"end": {
"type": "number",
"description": "页面结束时间(秒)"
},
"groups": {
"type": "array",
"description": "句子组数组",
"items": {
"type": "object",
"properties": {
"sentence": {
"type": "string",
"description": "英文句子"
},
"sentence_cn": {
"type": "string",
"description": "中文翻译"
},
"start": {
"type": "number",
"description": "句子开始时间(秒)"
},
"end": {
"type": "number",
"description": "句子结束时间(秒)"
},
"reason": {
"type": ["string", "null"],
"description": "处理原因说明,可能为 null"
},
"group": {
"type": "array",
"description": "文本组数组",
"items": {
"type": "object",
"properties": {
"rect": {
"type": "object",
"properties": {
"x": {
"type": "string",
"pattern": "^[0-9]+\\.[0-9]+$",
"description": "矩形区域 X 坐标(相对于图片尺寸的位置)"
},
"y": {
"type": "string",
"pattern": "^[0-9]+\\.[0-9]+$",
"description": "矩形区域 Y 坐标(相对于图片尺寸的位置)"
},
"width": {
"type": "string",
"pattern": "^[0-9]+\\.[0-9]+$",
"description": "矩形区域宽度(相对于图片尺寸的位置)"
},
"height": {
"type": "string",
"pattern": "^[0-9]+\\.[0-9]+$",
"description": "矩形区域高度(相对于图片尺寸的位置)"
}
},
"required": ["x", "y", "width", "height"],
"additionalProperties": false
},
"text": {
"type": "string",
"description": "文本内容"
},
"words": {
"type": "array",
"description": "单词数组",
"items": {
"type": "object",
"properties": {
"text": {
"type": "string",
"description": "单词文本"
},
"rect": {
"type": "object",
"properties": {
"x": {
"type": "string",
"pattern": "^[0-9]+\\.[0-9]+$",
"description": "单词区域 X 坐标(相对于图片尺寸的位置)"
},
"y": {
"type": "string",
"pattern": "^[0-9]+\\.[0-9]+$",
"description": "单词区域 Y 坐标(相对于图片尺寸的位置)"
},
"width": {
"type": "string",
"pattern": "^[0-9]+\\.[0-9]+$",
"description": "单词区域宽度(相对于图片尺寸的位置)"
},
"height": {
"type": "string",
"pattern": "^[0-9]+\\.[0-9]+$",
"description": "单词区域高度(相对于图片尺寸的位置)"
}
},
"required": ["x", "y", "width", "height"],
"additionalProperties": false
},
"chars": {
"type": "array",
"description": "字符数组",
"items": {
"type": "object",
"properties": {
"text": {
"type": "string",
"description": "字符文本"
},
"rect": {
"type": "object",
"properties": {
"x": {
"type": "string",
"pattern": "^[0-9]+\\.[0-9]+$",
"description": "字符区域 X 坐标"
},
"y": {
"type": "string",
"pattern": "^[0-9]+\\.[0-9]+$",
"description": "字符区域 Y 坐标"
},
"width": {
"type": "string",
"pattern": "^[0-9]+\\.[0-9]+$",
"description": "字符区域宽度"
},
"height": {
"type": "string",
"pattern": "^[0-9]+\\.[0-9]+$",
"description": "字符区域高度"
}
},
"required": ["x", "y", "width", "height"],
"additionalProperties": false
}
},
"required": ["text", "rect"],
"additionalProperties": false
}
},
"start": {
"type": ["number", "null"],
"description": "单词开始时间(秒),可能为 null"
},
"end": {
"type": ["number", "null"],
"description": "单词结束时间(秒),可能为 null"
},
"reason": {
"type": ["string", "null"],
"description": "处理原因说明,可能为 null"
}
},
"required": ["text", "rect", "chars"],
"additionalProperties": false
}
}
},
"required": ["rect", "text", "words"],
"additionalProperties": false
}
}
},
"required": ["sentence", "sentence_cn", "start", "end", "reason", "group"],
"additionalProperties": false
}
}
},
"required": ["image_url", "page", "start", "end", "groups"],
"additionalProperties": false
}
}
},
"required": ["audio_url", "pages"],
"additionalProperties": false
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment