-
Notifications
You must be signed in to change notification settings - Fork 326
/
nemo_process.py
32 lines (26 loc) · 926 Bytes
/
nemo_process.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
import argparse
import os
import torch
from nemo.collections.asr.models.msdd_models import NeuralDiarizer
from pydub import AudioSegment
from helpers import create_config
parser = argparse.ArgumentParser()
parser.add_argument(
"-a", "--audio", help="name of the target audio file", required=True
)
parser.add_argument(
"--device",
dest="device",
default="cuda" if torch.cuda.is_available() else "cpu",
help="if you have a GPU use 'cuda', otherwise 'cpu'",
)
args = parser.parse_args()
# convert audio to mono for NeMo combatibility
sound = AudioSegment.from_file(args.audio).set_channels(1)
ROOT = os.getcwd()
temp_path = os.path.join(ROOT, "temp_outputs")
os.makedirs(temp_path, exist_ok=True)
sound.export(os.path.join(temp_path, "mono_file.wav"), format="wav")
# Initialize NeMo MSDD diarization model
msdd_model = NeuralDiarizer(cfg=create_config(temp_path)).to(args.device)
msdd_model.diarize()