yychao commited on
Commit
67df979
·
verified ·
1 Parent(s): b6f3b3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -9
app.py CHANGED
@@ -28,24 +28,18 @@ def get_embedding(waveform):
28
 
29
  # 主處理函式
30
  def compare_audio(native_audio, user_audio):
31
- print("1")
32
  native_wav = preprocess(native_audio)
33
- print("2")
34
  user_wav = preprocess(user_audio)
35
- print("3")
36
 
37
  if native_wav is None or user_wav is None:
38
  return "請上傳兩段語音"
39
 
40
- print("4")
41
  emb1 = get_embedding(native_wav)
42
- print("5")
43
  emb2 = get_embedding(user_wav)
44
- print("6")
45
  similarity = F.cosine_similarity(emb1, emb2).item()
46
- print("7")
47
  score = round(similarity * 100, 2) # 轉換為 0~100 分數
48
- print("8")
49
  # 評語
50
  if score > 90:
51
  feedback = "非常接近!你模仿得很好 👏"
@@ -59,7 +53,7 @@ def compare_audio(native_audio, user_audio):
59
  return f"相似度分數:{score}/100\n{feedback}"
60
 
61
  # Gradio UI
62
- title = "🎤 音模仿評分器"
63
  description = "上傳 native speaker 的語音,以及你模仿的語音,系統會幫你評分你的發音相似度。"
64
 
65
  demo = gr.Interface(
 
28
 
29
  # 主處理函式
30
  def compare_audio(native_audio, user_audio):
31
+
32
  native_wav = preprocess(native_audio)
 
33
  user_wav = preprocess(user_audio)
 
34
 
35
  if native_wav is None or user_wav is None:
36
  return "請上傳兩段語音"
37
 
 
38
  emb1 = get_embedding(native_wav)
 
39
  emb2 = get_embedding(user_wav)
 
40
  similarity = F.cosine_similarity(emb1, emb2).item()
 
41
  score = round(similarity * 100, 2) # 轉換為 0~100 分數
42
+
43
  # 評語
44
  if score > 90:
45
  feedback = "非常接近!你模仿得很好 👏"
 
53
  return f"相似度分數:{score}/100\n{feedback}"
54
 
55
  # Gradio UI
56
+ title = "🎤 語音模仿評分器"
57
  description = "上傳 native speaker 的語音,以及你模仿的語音,系統會幫你評分你的發音相似度。"
58
 
59
  demo = gr.Interface(