Spaces:
Runtime error
Runtime error
Update app_utils.py
Browse files- app_utils.py +1 -51
app_utils.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import torch
|
2 |
import time
|
3 |
import numpy as np
|
@@ -43,57 +44,6 @@ def text_api(text:str):
|
|
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):
|
58 |
-
# print(type(audio))
|
59 |
-
# print(audio)
|
60 |
-
# sample_rate, signal = (audio) # 这是语音的输入
|
61 |
-
# signal = signal.astype(np.float32)
|
62 |
-
# signal /= np.max(np.abs(signal))
|
63 |
-
# sf.write("data/a.wav", signal, sample_rate)
|
64 |
-
# signal, sample_rate = torchaudio.load("data/a.wav")
|
65 |
-
# signal1 = torchaudio.transforms.Resample(orig_freq=sample_rate, new_freq=16000)(
|
66 |
-
# signal
|
67 |
-
# )
|
68 |
-
# torchaudio.save("data/out.wav", signal1, 16000, encoding="PCM_S", bits_per_sample=16)
|
69 |
-
# Audio = "data/out.wav"
|
70 |
-
# speech, sample_rate = AudioReader.read_wav_file(Audio)
|
71 |
-
# if signal == "none":
|
72 |
-
# return "none", "none", "haha"
|
73 |
-
# else:
|
74 |
-
# segments = vad.segments_offline(speech)
|
75 |
-
# text_results = ""
|
76 |
-
# for part in segments:
|
77 |
-
# _result = ASR_model.infer_offline(
|
78 |
-
# speech[part[0] * 16 : part[1] * 16], hot_words="任意热词 空格分开"
|
79 |
-
# )
|
80 |
-
# text_results += punc.punctuate(_result)[0]
|
81 |
-
|
82 |
-
# out_prob, score, index, text_lab = classifier.classify_batch(signal1)
|
83 |
-
# print(type(out_prob.squeeze(0).numpy()))
|
84 |
-
# print(out_prob.squeeze(0).numpy())
|
85 |
-
# print(type(text_lab[-1]))
|
86 |
-
# print(text_lab[-1])
|
87 |
-
# return text_results, out_prob.squeeze(0).numpy(), text_lab[-1], 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 |
#规范函数,只管值输入输出:
|
99 |
def text_score(text):
|
|
|
1 |
+
import gradio as gr
|
2 |
import torch
|
3 |
import time
|
4 |
import numpy as np
|
|
|
44 |
)
|
45 |
return result
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
#######################################################################
|
48 |
#规范函数,只管值输入输出:
|
49 |
def text_score(text):
|