Liusuthu commited on
Commit
b997bf2
1 Parent(s): 03aee8a

Update speech.py

Browse files
Files changed (1) hide show
  1. speech.py +14 -10
speech.py CHANGED
@@ -59,17 +59,21 @@ def text_score(text):
59
  else:
60
  string=text_api(text)
61
  print(string)
62
- part1 = str.partition(string, r"text")
63
- want1 = part1[2]
64
- label = want1[4:6]
65
- part2 = str.partition(string, r"probability")
66
- want2 = part2[2]
67
- prob = float(want2[3:-4])
68
- if label=="正向":
69
- score=-np.log10(prob*10)
70
  else:
71
- score=np.log10(prob*10)
72
- # print("from func:text_score————,text:",text,",score:",score)
 
 
 
 
 
 
 
 
 
73
  return text,score
74
 
75
  def speech_score(audio):
 
59
  else:
60
  string=text_api(text)
61
  print(string)
62
+ if string=="[{}]":
63
+ text="空"
64
+ score=0
 
 
 
 
 
65
  else:
66
+ part1 = str.partition(string, r"text")
67
+ want1 = part1[2]
68
+ label = want1[4:6]
69
+ part2 = str.partition(string, r"probability")
70
+ want2 = part2[2]
71
+ prob = float(want2[3:-4])
72
+ if label=="正向":
73
+ score=-np.log10(prob*10)
74
+ else:
75
+ score=np.log10(prob*10)
76
+ # print("from func:text_score————,text:",text,",score:",score)
77
  return text,score
78
 
79
  def speech_score(audio):