Remove emoji from spoken display name

main
Bob Mottram 2021-03-03 18:24:37 +00:00
parent d2b084b0dc
commit d6f4bc15ba
2 changed files with 21 additions and 0 deletions

View File

@ -86,6 +86,7 @@ from content import htmlReplaceQuoteMarks
from speaker import speakerReplaceLinks from speaker import speakerReplaceLinks
from speaker import speakerPronounce from speaker import speakerPronounce
from speaker import speakerEndpointJson from speaker import speakerEndpointJson
from speaker import removeEmojiFromText
def storeHashTags(baseDir: str, nickname: str, postJsonObject: {}) -> None: def storeHashTags(baseDir: str, nickname: str, postJsonObject: {}) -> None:
@ -2201,6 +2202,7 @@ def _updateSpeaker(baseDir: str, nickname: str, domain: str,
getDisplayName(baseDir, postJsonObject['actor'], personCache) getDisplayName(baseDir, postJsonObject['actor'], personCache)
if not speakerName: if not speakerName:
return return
speakerName = removeEmojiFromText(speakerName)
gender = getGenderFromBio(baseDir, postJsonObject['actor'], gender = getGenderFromBio(baseDir, postJsonObject['actor'],
personCache, translate) personCache, translate)
if announcingActor: if announcingActor:

View File

@ -171,6 +171,25 @@ def _addSSMLemphasis(sayText: str) -> str:
return sayText return sayText
def removeEmojiFromText(sayText: str) -> str:
"""Removes :emoji: from the given text
"""
if '*' not in sayText:
return sayText
text = sayText
for ch in speakerRemoveChars:
text = text.replace(ch, ' ')
wordsList = text.split(' ')
replacements = {}
for word in wordsList:
if word.startswith(':'):
if word.endswith(':'):
replacements[word] = word.replace('*', '')
for replaceStr, newStr in replacements.items():
sayText = sayText.replace(replaceStr, newStr)
return sayText.replace(' ', ' ').strip()
def getSpeakerFromServer(baseDir: str, session, def getSpeakerFromServer(baseDir: str, session,
nickname: str, password: str, nickname: str, password: str,
domain: str, port: int, domain: str, port: int,