File size: 641 Bytes
597a3c5
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# This is used to detect the spoken language in an audio file
# I wanted to abstract it to it's own file, just like vocal isolation & diarization
from speechbrain.pretrained import EncoderClassifier

language_identifier_model = None

def detect_language(file):
	global language_identifier_model
	if not language_identifier_model:
		language_identifier_model = EncoderClassifier.from_hparams(source="speechbrain/lang-id-voxlingua107-ecapa", savedir="tmp") #, run_opts={"device":"cuda"})
	signal = language_identifier_model.load_audio(file)
	prediction = language_identifier_model.classify_batch(signal)
	return prediction[3][0].split(' ')[1]