Spaces:
Runtime error
Runtime error
Update app_utils.py
Browse files- app_utils.py +13 -66
app_utils.py
CHANGED
@@ -43,15 +43,15 @@ def text_api(text:str):
|
|
43 |
)
|
44 |
return result
|
45 |
|
46 |
-
def get_text_score(text):
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
|
56 |
|
57 |
def classify_continuous(audio):
|
@@ -88,64 +88,11 @@ def classify_continuous(audio):
|
|
88 |
|
89 |
|
90 |
|
91 |
-
def preprocess_image_and_predict(inp):
|
92 |
-
|
93 |
-
|
94 |
-
def preprocess_video_and_predict(video):
|
95 |
-
return None, None, None, None
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
def text_api(text:str):
|
100 |
-
result = client.predict(
|
101 |
-
text, # str in '输入文字' Textbox component
|
102 |
-
api_name="/predict",
|
103 |
-
)
|
104 |
-
return result
|
105 |
-
|
106 |
-
|
107 |
-
def get_text_score(text):
|
108 |
-
string=text_api(text)
|
109 |
-
part1 = str.partition(string, r"text")
|
110 |
-
want1 = part1[2]
|
111 |
-
label = want1[4:6]
|
112 |
-
part2 = str.partition(string, r"probability")
|
113 |
-
want2 = part2[2]
|
114 |
-
prob = float(want2[3:-4])
|
115 |
-
return label, prob
|
116 |
-
|
117 |
-
def classify_continuous(audio):
|
118 |
-
print(type(audio))
|
119 |
-
print(audio)
|
120 |
-
sample_rate, signal = audio # 这是语音的输入
|
121 |
-
signal = signal.astype(np.float32)
|
122 |
-
signal /= np.max(np.abs(signal))
|
123 |
-
sf.write("data/a.wav", signal, sample_rate)
|
124 |
-
signal, sample_rate = torchaudio.load("data/a.wav")
|
125 |
-
signal1 = torchaudio.transforms.Resample(orig_freq=sample_rate, new_freq=16000)(
|
126 |
-
signal
|
127 |
-
)
|
128 |
-
torchaudio.save("data/out.wav", signal1, 16000, encoding="PCM_S", bits_per_sample=16)
|
129 |
-
Audio = "data/out.wav"
|
130 |
-
speech, sample_rate = AudioReader.read_wav_file(Audio)
|
131 |
-
if signal == "none":
|
132 |
-
return "none", "none", "haha"
|
133 |
-
else:
|
134 |
-
segments = vad.segments_offline(speech)
|
135 |
-
text_results = ""
|
136 |
-
for part in segments:
|
137 |
-
_result = ASR_model.infer_offline(
|
138 |
-
speech[part[0] * 16 : part[1] * 16], hot_words="任意热词 空格分开"
|
139 |
-
)
|
140 |
-
text_results += punc.punctuate(_result)[0]
|
141 |
-
|
142 |
-
out_prob, score, index, text_lab = classifier.classify_batch(signal1)
|
143 |
-
print(type(out_prob.squeeze(0).numpy()))
|
144 |
-
print(out_prob.squeeze(0).numpy())
|
145 |
-
print(type(text_lab[-1]))
|
146 |
-
print(text_lab[-1])
|
147 |
-
return text_results, out_prob.squeeze(0).numpy(), text_lab[-1], Audio
|
148 |
|
|
|
|
|
149 |
|
150 |
#######################################################################
|
151 |
#规范函数,只管值输入输出:
|
|
|
43 |
)
|
44 |
return result
|
45 |
|
46 |
+
# def get_text_score(text):
|
47 |
+
# string=text_api(text)
|
48 |
+
# part1 = str.partition(string, r"text")
|
49 |
+
# want1 = part1[2]
|
50 |
+
# label = want1[4:6]
|
51 |
+
# part2 = str.partition(string, r"probability")
|
52 |
+
# want2 = part2[2]
|
53 |
+
# prob = float(want2[3:-4])
|
54 |
+
# return label, prob
|
55 |
|
56 |
|
57 |
def classify_continuous(audio):
|
|
|
88 |
|
89 |
|
90 |
|
91 |
+
# def preprocess_image_and_predict(inp):
|
92 |
+
# return None, None, None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
+
# def preprocess_video_and_predict(video):
|
95 |
+
# return None, None, None, None
|
96 |
|
97 |
#######################################################################
|
98 |
#规范函数,只管值输入输出:
|