nazemi commited on
Commit
961974f
·
verified ·
1 Parent(s): 5d56a3e

Upload id_finetuned_model.py

Browse files
Files changed (1) hide show
  1. id_finetuned_model.py +23 -0
id_finetuned_model.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import sys
3
+ import time
4
+ class LI:
5
+ def __init__(self, model_name="language_identification"):
6
+
7
+ self.pipe = pipeline("automatic-speech-recognition", model=model_name, return_language=True)
8
+ def detect_language(self, audio_file_path):
9
+ result = self.pipe(audio_file_path)
10
+ if 'chunks' in result and result['chunks']:
11
+ language = result['chunks'][0]['language']
12
+ else:
13
+ language = result.get('language', 'Unknown')
14
+ return language
15
+
16
+ if __name__ == "__main__":
17
+ li = LI()
18
+ audio_file_path = sys.argv[1]
19
+ s =time.time()
20
+ language = li.detect_language(audio_file_path)
21
+ e =time.time()
22
+ print(f"Detected language: {language}", e -s)
23
+