Spaces:
Runtime error
Runtime error
Strip invisible speech input characters
Browse files- app.py +4 -4
- 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
|
| 118 |
-
|
| 119 |
-
|
| 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
|
| 67 |
-
|
| 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 |
}
|