Irpan
commited on
Commit
·
18f99c6
1
Parent(s):
f6cde70
app
Browse files
util.py
CHANGED
@@ -1,10 +1,8 @@
|
|
1 |
import random
|
2 |
from umsc import UgMultiScriptConverter
|
3 |
-
import torchaudio
|
4 |
import string
|
5 |
import epitran
|
6 |
from difflib import SequenceMatcher
|
7 |
-
import numpy as np
|
8 |
|
9 |
# Lists of Uyghur short and long texts
|
10 |
short_texts = [
|
@@ -36,23 +34,23 @@ def generate_long_text(script_choice):
|
|
36 |
return text
|
37 |
|
38 |
# ASR Utils
|
39 |
-
def load_and_resample_audio(audio_data, target_rate):
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
|
57 |
def calculate_pronunciation_accuracy(reference_text, output_text, language_code='uig-Arab'):
|
58 |
"""
|
|
|
1 |
import random
|
2 |
from umsc import UgMultiScriptConverter
|
|
|
3 |
import string
|
4 |
import epitran
|
5 |
from difflib import SequenceMatcher
|
|
|
6 |
|
7 |
# Lists of Uyghur short and long texts
|
8 |
short_texts = [
|
|
|
34 |
return text
|
35 |
|
36 |
# ASR Utils
|
37 |
+
# def load_and_resample_audio(audio_data, target_rate):
|
38 |
+
# """Load audio and resample based on target sample rate"""
|
39 |
+
# if isinstance(audio_data, tuple):
|
40 |
+
# # microphone
|
41 |
+
# sampling_rate, audio_input = audio_data
|
42 |
+
# audio_input = (audio_input / 32768.0).astype(np.float32)
|
43 |
+
# elif isinstance(audio_data, str):
|
44 |
+
# # file upload
|
45 |
+
# audio_input, sampling_rate = torchaudio.load(audio_data)
|
46 |
+
# else:
|
47 |
+
# return "<<ERROR: Invalid Audio Input Instance: {}>>".format(type(audio_data))
|
48 |
+
# # Resample if needed
|
49 |
+
# if sampling_rate != target_rate:
|
50 |
+
# resampler = torchaudio.transforms.Resample(sampling_rate, target_rate)
|
51 |
+
# audio_input = resampler(audio_input)
|
52 |
+
|
53 |
+
# return audio_input, target_rate
|
54 |
|
55 |
def calculate_pronunciation_accuracy(reference_text, output_text, language_code='uig-Arab'):
|
56 |
"""
|