Mihaj commited on
Commit
bc54321
·
verified ·
1 Parent(s): 40e6055

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -2
app.py CHANGED
@@ -135,6 +135,42 @@ def percent_V(vowels, total_wo_pauses):
135
  return pV
136
 
137
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
 
139
  def transcribe(audio):
140
  y, sr = sf.read(audio)
@@ -163,7 +199,7 @@ def transcribe(audio):
163
  dC = delta_C(cons_clusters)
164
  pV = percent_V(vowels_duration, duration_without_pauses)
165
 
166
- transcription = processor.decode(predicted_ids[0]).lower()
167
 
168
  text = {"transcription": transcription}
169
 
@@ -178,7 +214,7 @@ iface = gr.Interface(
178
  inputs=gr.Audio(type="filepath"),
179
  outputs="text",
180
  title="Mihaj/Wav2Vec2RhytmAnalyzer",
181
- description="Демо анализатор ритма на основе модели Wav2Vec large от bond005. Максимум обрабатываемой длительности записи - 10 секунд.",
182
  )
183
 
184
  iface.launch()
 
135
  return pV
136
 
137
 
138
+ # point_1 = np.array((0, 0, 0))
139
+ # point_2 = np.array((3, 3, 3))
140
+ def count_eucl(point_1, point_2):
141
+ # Initializing the points
142
+ # Get the square of the difference of the 2 vectors
143
+ square = np.square(point_1 - point_2)
144
+ # Get the sum of the square
145
+ sum_square = np.sum(square)
146
+ # The last step is to get the square root and print the Euclidean distance
147
+ distance = np.sqrt(sum_square)
148
+ return distance
149
+
150
+
151
+ ex_dict = {"eng": np.array((0.0535, 0.401)), "kat": np.array((0.0452, 0.456)), "jap": np.array((0.0356, 0.531))}
152
+
153
+
154
+ def classify_rhytm(dC, pV):
155
+ our = np.array((dC, pV))
156
+ res = {}
157
+ if (dC > 0.08 and pV > 0.45) or (dC < 0.03 and pV < 0.04):
158
+ text = "Вы не укладываетесь ни в какие рамки и прекрасны в этом!"
159
+ else:
160
+ for k, v in ex_dict.items():
161
+ res[k] = count_eucl(our, v)
162
+
163
+ sorted_tuples = sorted(res.items(), key=lambda item: item[1])
164
+ sorted_res = {k: v for k, v in sorted_tuples}
165
+ if sorted_res.keys()[0] == "eng":
166
+ text = "По типу ритма ваша речь близка к тактосчитающим языкам (английский)."
167
+ if sorted_res.keys()[0] == "kat":
168
+ text = "По типу ритма ваша речь близка к слогосчитающим языкам (испанский)."
169
+ if sorted_res.keys()[0] == "jap":
170
+ text = "По типу ритма ваша речь близка к моросчитающим языкам (японский)."
171
+ return text
172
+
173
+
174
 
175
  def transcribe(audio):
176
  y, sr = sf.read(audio)
 
199
  dC = delta_C(cons_clusters)
200
  pV = percent_V(vowels_duration, duration_without_pauses)
201
 
202
+ transcription = processor.decode(predicted_ids).lower()
203
 
204
  text = {"transcription": transcription}
205
 
 
214
  inputs=gr.Audio(type="filepath"),
215
  outputs="text",
216
  title="Mihaj/Wav2Vec2RhytmAnalyzer",
217
+ description="Демо анализатор ритма на основе модели Wav2Vec large от bond005.",
218
  )
219
 
220
  iface.launch()