File size: 1,319 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/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/voice_clone_audio/e2_tts/audio_0_3_clone_from_audio_0_2.wav").as_posix(),
        type=str,
    )
    parser.add_argument(
        "--output_file",
        default="temp.wav",
        type=str,
    )
    parser.add_argument("--change_by_radio", default=0.5, type=float)
    args = parser.parse_args()
    return args


def change_by_ratio(signal: np.ndarray, radio: float = 1.0):
    signal_ = signal * radio
    signal_ = np.clip(signal_, a_min=0.0, a_max=1.0)
    return signal_


def main():
    args = get_args()

    signal, sample_rate = librosa.load(args.filename)

    signal_ = change_by_ratio(
        signal=signal,
        radio=args.change_by_radio,
    )
    # max_wave_value = 32768.0
    max_wave_value = 1 << 15

    signal_ = signal_ * max_wave_value
    signal_ = np.array(signal_, dtype=np.int16)

    wavfile.write(
        filename=args.output_file,
        rate=sample_rate,
        data=signal_

    )
    return


if __name__ == "__main__":
    main()