forked from SpeechColab/GigaSpeech
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opus_to_wav.py
executable file
·40 lines (30 loc) · 1021 Bytes
/
opus_to_wav.py
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
# Copyright 2021 Xiaomi (Author:Yongqing Wang)
import os
import argparse
import re
def get_args():
parser = argparse.ArgumentParser(description="""
This script is used to convert opus file into wav file.""")
parser.add_argument('--remove-opus', action='store_true', default='False',
help="""If true, remove opus files""")
parser.add_argument('opus_scp', help="""Input opus scp file""")
args = parser.parse_args()
return args
def convert_opus2wav(opus_scp, rm_opus):
with open(opus_scp, 'r') as oscp:
for line in oscp:
line = line.strip()
utt, opus_path = re.split('\s+', line)
wav_path = opus_path.replace('.opus', '.wav')
cmd = f'ffmpeg -y -i {opus_path} -ac 1 -ar 16000 {wav_path}'
try:
os.system(cmd)
except:
sys.exit(f'Failed to run the cmd: {cmd}')
if rm_opus is True:
os.remove(opus_path)
def main():
args = get_args()
convert_opus2wav(args.opus_scp, args.remove_opus)
if __name__ == '__main__':
main()