File size: 742 Bytes
961974f 47760b6 961974f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
from transformers import pipeline
import sys
import time
class LI:
def __init__(self, model_name="language-identification"):
self.pipe = pipeline("automatic-speech-recognition", model=model_name, return_language=True)
def detect_language(self, audio_file_path):
result = self.pipe(audio_file_path)
if 'chunks' in result and result['chunks']:
language = result['chunks'][0]['language']
else:
language = result.get('language', 'Unknown')
return language
if __name__ == "__main__":
li = LI()
audio_file_path = sys.argv[1]
s =time.time()
language = li.detect_language(audio_file_path)
e =time.time()
print(f"Detected language: {language}", e -s)
|