summaryrefslogtreecommitdiffstats
path: root/dom/media/webaudio/test/generate-test-files.py
blob: af4bc3bb4932642f1d5aebd3f91c531b8a328842 (plain)
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
#!/usr/bin/env python3

import os

rates = [44100, 48000]
channels = [1, 2]
duration = "0.5"
frequency = "1000"
volume = "-3dB"
name = "half-a-second"
formats = {
    "aac-in-adts": [{"codec": "aac", "extension": "aac"}],
    "mp3": [{"codec": "libmp3lame", "extension": "mp3"}],
    "mp4": [
        {
            "codec": "libopus",
            "extension": "mp4",
        },
        {"codec": "aac", "extension": "mp4"},
    ],
    "ogg": [
        {"codec": "libvorbis", "extension": "ogg"},
        {"codec": "libopus", "extension": "opus"},
    ],
    "flac": [
        {"codec": "flac", "extension": "flac"},
    ],
    "webm": [
        {"codec": "libopus", "extension": "webm"},
        {"codec": "libvorbis", "extension": "webm"},
    ],
}

for rate in rates:
    for channel_count in channels:
        wav_filename = "{}-{}ch-{}.wav".format(name, channel_count, rate)
        wav_command = "sox -V -r {} -n -b 16 -c {} {}  synth {} sin {} vol {}".format(
            rate, channel_count, wav_filename, duration, frequency, volume
        )
        print(wav_command)
        os.system(wav_command)
        for container, codecs in formats.items():
            for codec in codecs:
                encoded_filename = "{}-{}ch-{}-{}.{}".format(
                    name, channel_count, rate, codec["codec"], codec["extension"]
                )
                print(encoded_filename)
                encoded_command = "ffmpeg -y -i {} -acodec {} {}".format(
                    wav_filename, codec["codec"], encoded_filename
                )
                print(encoded_command)
                os.system(encoded_command)