3v324v23 commited on
Commit
8005544
·
1 Parent(s): ee3b233

Strip invisible speech input characters

Browse files
Files changed (2) hide show
  1. app.py +4 -4
  2. static/app.js +2 -3
app.py CHANGED
@@ -112,12 +112,12 @@ async def _backend_status() -> tuple[bool, dict]:
112
 
113
 
114
  def _normalize_speech_text(text: str) -> str:
 
115
  cleaned: list[str] = []
116
  for character in text:
117
- if character.isspace():
118
- cleaned.append(" ")
119
- elif unicodedata.category(character) not in {"Cc", "Cf", "Cs", "Co", "Cn"}:
120
- cleaned.append(character)
121
  return " ".join("".join(cleaned).split())
122
 
123
 
 
112
 
113
 
114
  def _normalize_speech_text(text: str) -> str:
115
+ text = text.replace("\\n", "").replace("\\r", "").replace("\\t", "")
116
  cleaned: list[str] = []
117
  for character in text:
118
+ if unicodedata.category(character) in {"Cc", "Cf", "Cs", "Co", "Cn"}:
119
+ continue
120
+ cleaned.append(" " if character.isspace() else character)
 
121
  return " ".join("".join(cleaned).split())
122
 
123
 
static/app.js CHANGED
@@ -63,9 +63,8 @@ function formatDuration(seconds) {
63
  }
64
 
65
  function normalizeSpeechText(value, trim = true) {
66
- const withoutInvisible = value.replace(INVISIBLE_CHARACTERS, (character) => (
67
- /\s/.test(character) ? " " : ""
68
- ));
69
  const normalized = withoutInvisible.replace(/\s+/g, " ");
70
  return trim ? normalized.trim() : normalized;
71
  }
 
63
  }
64
 
65
  function normalizeSpeechText(value, trim = true) {
66
+ const withoutEscapes = value.replace(/\\[nrt]/g, "");
67
+ const withoutInvisible = withoutEscapes.replace(INVISIBLE_CHARACTERS, "");
 
68
  const normalized = withoutInvisible.replace(/\s+/g, " ");
69
  return trim ? normalized.trim() : normalized;
70
  }