Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions src/isomorphic-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, ' ');
}

/**
Expand Down Expand Up @@ -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}`;
}
}