File size: 944 Bytes
a8c8d73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import argparse

import librosa
import numpy as np
from scipy.io import wavfile

from project_settings import project_path


def get_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--filename",
        default=(project_path / "data/常相伴AI配音9.10/常相伴AI配音9.10/台湾-女声/1.m4a").as_posix(),
        type=str,
    )
    parser.add_argument(
        "--output_file",
        default="temp.wav",
        type=str,
    )
    args = parser.parse_args()
    return args


def main():
    args = get_args()

    max_wave_value = 32768.0

    signal, sample_rate = librosa.load(args.filename, sr=8000)
    signal *= max_wave_value
    signal = np.array(signal, dtype=np.int16)
    print(signal.dtype)
    print(sample_rate)

    wavfile.write(
        args.output_file,
        8000,
        signal,
    )
    return


if __name__ == "__main__":
    main()