-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_2.py
More file actions
25 lines (21 loc) · 893 Bytes
/
Copy pathtest_2.py
File metadata and controls
25 lines (21 loc) · 893 Bytes
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
from pydub import AudioSegment
import requests
import argparse
import json
import sys
import io
parser = argparse.ArgumentParser(description='Расшифровка аудио в текст.')
parser.add_argument('--in_file', required=True, help='аудио файл')
parser.add_argument('--log_file', default='log.json', help='лог файл')
parser.add_argument('--asr_url', default='http://0.0.0.0:2600/asr_file', help='адрес сервера')
args = parser.parse_args()
sound = AudioSegment.from_file(args.in_file).set_frame_rate(16000).set_sample_width(2)
channels = sound.split_to_mono()
f_wav = io.BytesIO()
with open(args.log_file, 'a') as out:
for channel in channels:
channel.export(f_wav, format="raw")
response = requests.post(args.asr_url, data = f_wav)
json.dump(response.json(), out)
out.write('\n')
print(response.json())