/
examples.ts
104 lines (99 loc) · 2.92 KB
/
examples.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { writeFileSync } from "fs"
import { MediaFile } from "./metadata"
// A simple example that might be generated from an MP4 video and two SRT
// subtitle files.
const subtitleExample: MediaFile = {
baseTrack: {
type: "media",
lang: "fr",
file: "episode1.mp4",
},
alignments: [
{
timeSpan: [10, 15.5],
tracks: [
{
type: "html",
lang: "fr",
html: "<i>Jean & Luc:</i> On y va !"
},
{
type: "html",
lang: "en",
html: "<i>Jean & Luc:</i> Let's go!"
},
],
},
],
};
// A version of `subtitle_example`, except that now we've extracted PNG images
// and MP3 audio for each subtitle.
const subtitleExtractedExample: MediaFile = {
baseTrack: {
type: "media",
lang: "fr",
file: "episode1.mp4",
},
alignments: [
{
timeSpan: [10, 15.5],
tracks: [
{
type: "html",
lang: "fr",
html: "<i>Jean & Luc:</i> On y va !"
},
{
type: "html",
lang: "en",
html: "<i>Jean & Luc:</i> Let's go!"
},
{
type: "image",
// This is just an image from the video, so it has no
// `lang` element.
file: "episode1_12_75.jpg",
},
{
type: "media",
lang: "fr",
file: "episode1_9_00_16_50.mp3",
},
],
},
],
}
// And now for something different: Parallel texts with no media file.
const bookExample: MediaFile = {
// No `baseTrack` element because we have no input media file.
alignments: [
{
tracks: [
{
type: "html",
lang: "fr",
html: "<i>Jean & Luc:</i> On y va !"
},
{
type: "html",
lang: "en",
html: "<i>Jean & Luc:</i> Let's go!"
},
],
},
],
}
/**
* Write out an example as an actual JSON file.
*
* @param name The base name of the example directory.
* @param metadata The metadata to write as JSON.
*/
function writeExampleSync(name: string, metadata: MediaFile) {
const json = JSON.stringify(metadata, null, 2)
writeFileSync(`examples/${name}.aligned/metadata.json`, json)
}
// Write our our examples as JSON.
writeExampleSync("subtitle_example", subtitleExample)
writeExampleSync("subtitle_extracted_example", subtitleExtractedExample)
writeExampleSync("book_example", bookExample)