Remove punctuation

This commit is contained in:
Ruben van de Ven 2020-02-28 16:57:23 +03:00
parent b9196db157
commit 9cd98367cd

View file

@ -20,10 +20,13 @@ from hugvey.communication import LOG_BS
import audioop import audioop
import gc import gc
import time import time
import string
mainLogger = logging.getLogger("hugvey") mainLogger = logging.getLogger("hugvey")
logger = mainLogger.getChild("google") logger = mainLogger.getChild("google")
punctuationTranslation = str.maketrans('','',string.punctuation)
class RequireRestart(Exception): class RequireRestart(Exception):
pass pass
@ -176,6 +179,13 @@ class GoogleVoiceClient(object):
self.logger.info(f"Text: {transcript}") self.logger.info(f"Text: {transcript}")
self.lastNonFinalTranscript = None self.lastNonFinalTranscript = None
# if any(p in transcript for p in string.punctuation):
# self.logger.warning(f"Google returned punctuation in the string. It is removed: {transcript}")
# remove any possible punctuation from string. As google has sometimes
# given results _with_ punctuation, even though it should not?
transcript = transcript.translate(punctuationTranslation)
if result.is_final: if result.is_final:
self.logger.info("native final") self.logger.info("native final")
msg = { msg = {