diff --git a/src/isomorphic-utils.ts b/src/isomorphic-utils.ts index 65543a9..c1a4051 100644 --- a/src/isomorphic-utils.ts +++ b/src/isomorphic-utils.ts @@ -117,14 +117,8 @@ export function dateToString(date?: Date): string { * XML special characters (&<>"') are handled by the escape() function. */ export function removeIncompatibleCharacters(str: string): string { - // Keep essential punctuation for natural speech: .?;:!, - // Remove characters that could break SSML structure or cause parsing issues - const chars_to_remove = "*/()[]{}$%^@#+=|\\~`><\"&"; - let clean_str = str; - for (const char of chars_to_remove) { - clean_str = clean_str.replace(new RegExp('\\' + char, 'g'), ''); - } - return clean_str; + // Remove control characters except for \t, \n, \r + return str.replaceAll(/[\p{C}--[\t\r\n]]/gv, ' '); } /** @@ -193,4 +187,4 @@ export function calcMaxMesgSize(voiceConfig: TTSConfig): number { */ export function ssmlHeadersPlusData(requestId: string, timestamp: string, ssml: string): string { return `X-RequestId:${requestId}\r\nContent-Type:application/ssml+xml\r\nX-Timestamp:${timestamp}Z\r\nPath:ssml\r\n\r\n${ssml}`; -} \ No newline at end of file +}