commit f27f1860320c2665cbd6c9a001af9b5bb262962a
Author: Robert Haschke <rhaschke@techfak.uni-bielefeld.de>
Date:   Fri Nov 13 23:55:43 2020 +0100

    Fix indentation + whitespace

diff --git a/tts_bridge/mary/mary_tts_bridge/MaryTTSBridge.py b/tts_bridge/mary/mary_tts_bridge/MaryTTSBridge.py
index 04f94d4..a7e0127 100644
--- a/tts_bridge/mary/mary_tts_bridge/MaryTTSBridge.py
+++ b/tts_bridge/mary/mary_tts_bridge/MaryTTSBridge.py
@@ -42,111 +42,108 @@ try:
 except ImportError:
     from cStringIO import StringIO
 
-class MaryTTSBridge(object):
-    #_feedback = ttsActionFeedback()
-    #_result   = ttsActionResult()
 
+class MaryTTSBridge(object):
+    # _feedback = ttsActionFeedback()
+    # _result   = ttsActionResult()
 
     def __init__(self, topic, voice="cmu-slt-hsmm", locale="en_GB", tts_host="127.0.0.1", tts_port=59125, loglevel=logging.WARNING):
-	"""initialise
-	:param  loglevel: optional log level
-	"""
-	self.loglevel = loglevel
-	self.logger = logging.getLogger(__name__)
-	# create nice and actually usable formatter and add it to the handler
-	self.config_logger(loglevel)
-	self.logger.info("starting MaryTTSBridge on topic '"+topic+"'")
-
-	self.tts_client = MaryTTSClient(voice, locale, tts_host, tts_port, loglevel)
+        """initialise
+        :param  loglevel: optional log level
+        """
+        self.loglevel = loglevel
+        self.logger = logging.getLogger(__name__)
+        # create nice and actually usable formatter and add it to the handler
+        self.config_logger(loglevel)
+        self.logger.info("starting MaryTTSBridge on topic '"+topic+"'")
 
-	rospy.init_node('MaryTTSBridge', anonymous=True)
-
-	self._action_name = topic
-	self._as = actionlib.SimpleActionServer(self._action_name, ttsAction, execute_cb = self.execute_cb, auto_start = False)
-	self._as.start()
+        self.tts_client = MaryTTSClient(voice, locale, tts_host, tts_port, loglevel)
 
+        rospy.init_node('MaryTTSBridge', anonymous=True)
 
+        self._action_name = topic
+        self._as = actionlib.SimpleActionServer(self._action_name, ttsAction, execute_cb = self.execute_cb, auto_start = False)
+        self._as.start()
 
     def __del__(self):
-	"""destructor
-	"""
-	self.logger.debug("destructor of MaryTTSBridge called")
+        """destructor
+        """
+        self.logger.debug("destructor of MaryTTSBridge called")
 
     def config_logger(self, level):
-	"""initialise a nice logger formatting
-	:param  level: log level
-	"""
-	formatter = logging.Formatter('%(asctime)s %(name)-30s %(levelname)-8s > %(message)s')
-	ch = logging.StreamHandler()
-	#ch.setLevel(level)
-	ch.setFormatter(formatter)
-	self.logger.setLevel(level)
-	self.logger.addHandler(ch)
+        """initialise a nice logger formatting
+        :param  level: log level
+        """
+        formatter = logging.Formatter('%(asctime)s %(name)-30s %(levelname)-8s > %(message)s')
+        ch = logging.StreamHandler()
+        #ch.setLevel(level)
+        ch.setFormatter(formatter)
+        self.logger.setLevel(level)
+        self.logger.addHandler(ch)
 
     def create_soundchunk(self, audio_data):
-	#extract wave from data
-	fio = BytesIO(audio_data)
-	wav = wave.open(fio)
-
-	s = soundchunk()
-
-	s.channels = wav.getnchannels()
-	s.data = audio_data
-	s.endianess = s.ENDIAN_LITTLE #guessed?!
-	s.rate = wav.getframerate()
-	s.samplecount = wav.getnframes()
-
-
-	#sample format:
-	sample_width = wav.getsampwidth()
-	if (sample_width == 1):
-	    s.sample_type = s.SAMPLE_U8
-	elif (sample_width == 2):
-	    s.sample_type = s.SAMPLE_U16
-	elif (sample_width == 3):
-	    s.sample_type = s.SAMPLE_U24
-	else:
-	    self.logger.error("ERROR: invalid sample width "+str(sample_width) + " detected")
-	    s = soundchunk()
-
-	self.logger.info("created soundchunk with "+str(s.samplecount)+" samples")
-
-	return s
+        #extract wave from data
+        fio = BytesIO(audio_data)
+        wav = wave.open(fio)
+
+        s = soundchunk()
+
+        s.channels = wav.getnchannels()
+        s.data = audio_data
+        s.endianess = s.ENDIAN_LITTLE  # guessed?!
+        s.rate = wav.getframerate()
+        s.samplecount = wav.getnframes()
+
+        # sample format:
+        sample_width = wav.getsampwidth()
+        if (sample_width == 1):
+            s.sample_type = s.SAMPLE_U8
+        elif (sample_width == 2):
+            s.sample_type = s.SAMPLE_U16
+        elif (sample_width == 3):
+            s.sample_type = s.SAMPLE_U24
+        else:
+            self.logger.error("ERROR: invalid sample width "+str(sample_width) + " detected")
+            s = soundchunk()
+
+        self.logger.info("created soundchunk with "+str(s.samplecount)+" samples")
+
+        return s
 
     def create_phonemes(self, phoneme_bytes):
-	last = 0.0
-	plist = []
+        last = 0.0
+        plist = []
 
-	sio = StringIO(phoneme_bytes.decode('ascii'))
-	for line in sio:
-	    if (line[0] != '#'):
-		phoneme_list = line.split(" ")
+        sio = StringIO(phoneme_bytes.decode('ascii'))
+        for line in sio:
+            if (line[0] != '#'):
+                phoneme_list = line.split(" ")
                 if (line == '\n'):
-                    #ignore empty lines
+                    # ignore empty lines
                     continue
                 elif (len(phoneme_list) != 3):
                     print("> could not split line '%s' during phoneme seperation\n" % (line))
                 else:
-		    symbol = phoneme_list[2]
-    		    symbol = symbol.rstrip()
+                    symbol = phoneme_list[2]
+                    symbol = symbol.rstrip()
 
-   		    now = float(phoneme_list[0])
-		    duration = (now - last)*1000
-		    last = now
-		    plist.append(phoneme(symbol, int(duration)))
+                    now = float(phoneme_list[0])
+                    duration = (now - last)*1000
+                    last = now
+                    plist.append(phoneme(symbol, int(duration)))
 
-	self.logger.info("created phonemelist with " + str(len(plist)) + " elements")
+        self.logger.info("created phonemelist with " + str(len(plist)) + " elements")
 
-	return plist
+        return plist
 
     def create_utterance(self, text, audio_data, phoneme_list):
-	u = utterance()
-	u.text  = text
-	u.audio    = self.create_soundchunk(audio_data)
-	u.phonemes = self.create_phonemes(phoneme_list)
+        u = utterance()
+        u.text     = text
+        u.audio    = self.create_soundchunk(audio_data)
+        u.phonemes = self.create_phonemes(phoneme_list)
 
-	self.logger.info("created utterance for 'phonemelist with '" + u.text + "'")
-	return u
+        self.logger.info("created utterance for 'phonemelist with '" + u.text + "'")
+        return u
 
     def get_error_message(self):
         data_wav = pkgutil.get_data('mary_tts_bridge', 'data/connection_failed.wav')
@@ -154,38 +151,38 @@ class MaryTTSBridge(object):
         return (data_wav, data_phonemes)
 
     def execute_cb(self, goal):
-	self.logger.info("incoming utterance '" + goal.text + "'")
+        self.logger.info("incoming utterance '" + goal.text + "'")
 
-	success = True
-	result   = ttsResult()
+        success = True
+        result  = ttsResult()
 
-	#incoming msg, ask mary tts for data:
-	try:
-	    audio     = self.tts_client.generate_audio(goal.text)
-	    phonelist = self.tts_client.generate_phonemes(goal.text)
+        # incoming msg, ask mary tts for data:
+        try:
+            audio     = self.tts_client.generate_audio(goal.text)
+            phonelist = self.tts_client.generate_phonemes(goal.text)
 
-	except:
-	    self.logger.error("failed to create utterance error = '" + str(sys.exc_info()[1]) + "'")
-            #try to open error message from file:
+        except:
+            self.logger.error("failed to create utterance error = '" + str(sys.exc_info()[1]) + "'")
+            # try to open error message from file:
             success = True
             (audio, phonelist) = self.get_error_message()
 
-	if success:
-	    #build soundchunk
-	    result.utterance = self.create_utterance(goal.text, audio, phonelist)
-	    self._as.set_succeeded(result)
-	else:
-	    self._as.set_aborted(result)
+        if success:
+            # build soundchunk
+            result.utterance = self.create_utterance(goal.text, audio, phonelist)
+            self._as.set_succeeded(result)
+        else:
+            self._as.set_aborted(result)
 
     def run(self):
-	#run the main loop
-	rospy.spin()
+        # run the main loop
+        rospy.spin()
 
-#test code
+# test code
 def main():
     if (len(sys.argv) != 2):
-	print("> usage: "+sys.argv[0]+" <topic>\n\n")
-	sys.exit(1)
+        print("> usage: "+sys.argv[0]+" <topic>\n\n")
+        sys.exit(1)
 
     bridge = MaryTTSBridge(topic=sys.argv[1], loglevel=logging.INFO)
     bridge.run()
diff --git a/tts_bridge/mary/mary_tts_bridge/MaryTTSClient.py b/tts_bridge/mary/mary_tts_bridge/MaryTTSClient.py
index 7dbb59f..b774a02 100644
--- a/tts_bridge/mary/mary_tts_bridge/MaryTTSClient.py
+++ b/tts_bridge/mary/mary_tts_bridge/MaryTTSClient.py
@@ -26,103 +26,96 @@ Excellence Initiative.
 """
 
 import logging
-#try:
-#	import rsb
-#except ImportError:
-#	RSB_SUPPORT = False
-#else:
-#	from MiddlewareRSB import *
-#	RSB_SUPPORT = True
-
-#from MiddlewareROS import *
 import sys
 try:
-	from http.client import HTTPConnection
-	from urllib.parse import urlencode
+    from http.client import HTTPConnection
+    from urllib.parse import urlencode
 except ImportError:  # Python 2
-	from httplib import HTTPConnection
-	from urllib import urlencode
+    from httplib import HTTPConnection
+    from urllib import urlencode
 import wave
 import ctypes
 import wave
 import sys
 
+
 class MaryTTSClient:
     def __init__(self, voice="cmu-slt-hsmm", locale="en_US", tts_host="127.0.0.1", tts_port=59125, loglevel=logging.WARNING):
-	"""initialise
-	:param  loglevel: optional log level
-	"""
-	self.loglevel = loglevel
-	self.logger = logging.getLogger(__name__)
-	# create nice and actually usable formatter and add it to the handler
-	self.config_logger(loglevel)
+        """initialise
+        :param  loglevel: optional log level
+        """
+        self.loglevel = loglevel
+        self.logger = logging.getLogger(__name__)
+        # create nice and actually usable formatter and add it to the handler
+        self.config_logger(loglevel)
 
-	self.logger.info("starting MaryTTSClient (voice="+voice+", locale="+locale+", host="+tts_host+", port="+str(tts_port))
+        self.logger.info("starting MaryTTSClient (voice="+voice+", locale="+locale+", host="+tts_host+", port="+str(tts_port))
 
-	self.tts_host = tts_host
-	self.tts_port = tts_port
-	self.locale   = locale
-	self.voice    = voice
+        self.tts_host = tts_host
+        self.tts_port = tts_port
+        self.locale   = locale
+        self.voice    = voice
 
     def __del__(self):
-	"""destructor
-	"""
-	self.logger.debug("destructor of MaryTTSClient called")
+        """destructor
+        """
+        self.logger.debug("destructor of MaryTTSClient called")
 
     def config_logger(self, level):
-	"""initialise a nice logger formatting
-	:param  level: log level
-	"""
-	formatter = logging.Formatter('%(asctime)s %(name)-30s %(levelname)-8s > %(message)s')
-	ch = logging.StreamHandler()
-	#ch.setLevel(level)
-	ch.setFormatter(formatter)
-	self.logger.setLevel(level)
-	self.logger.addHandler(ch)
+        """initialise a nice logger formatting
+        :param  level: log level
+        """
+        formatter = logging.Formatter('%(asctime)s %(name)-30s %(levelname)-8s > %(message)s')
+        ch = logging.StreamHandler()
+        # ch.setLevel(level)
+        ch.setFormatter(formatter)
+        self.logger.setLevel(level)
+        self.logger.addHandler(ch)
 
     def generate_audio(self, message):
-	"""generate audio from text
-	:param message: text to synthesize
-	"""
-	return self.generate(message, "AUDIO")
+        """generate audio from text
+        :param message: text to synthesize
+        """
+        return self.generate(message, "AUDIO")
 
     def generate_phonemes(self, message):
-	"""generate phoneme list from text
-	:param message: text to synthesize
-	"""
-	return self.generate(message, "REALISED_DURATIONS")
+        """generate phoneme list from text
+        :param message: text to synthesize
+        """
+        return self.generate(message, "REALISED_DURATIONS")
 
     def generate(self, message, output_type):
-	"""generate requested data object from text
-	:param message: text to synthesize
-	"""
-
-	raw_params = {
-	    "INPUT_TEXT": message,
-	    "INPUT_TYPE": "RAWMARYXML",
-	    "OUTPUT_TYPE": output_type,
-	    "LOCALE": self.locale,
-	    "AUDIO": "WAVE_FILE",
-	    "VOICE": self.voice,
-	}
-
-	params = urlencode(raw_params)
-	headers = {}
-
-	#conn.set_debuglevel(5)
-	#open connection to mary server
+        """generate requested data object from text
+        :param message: text to synthesize
+        """
+
+        raw_params = {
+            "INPUT_TEXT": message,
+            "INPUT_TYPE": "RAWMARYXML",
+            "OUTPUT_TYPE": output_type,
+            "LOCALE": self.locale,
+            "AUDIO": "WAVE_FILE",
+            "VOICE": self.voice,
+        }
+
+        params = urlencode(raw_params)
+        headers = {}
+
+        # conn.set_debuglevel(5)
+        # open connection to mary server
         conn = HTTPConnection(self.tts_host, self.tts_port)
 
-	conn.request("POST", "/process", params, headers)
-	response = conn.getresponse()
+        conn.request("POST", "/process", params, headers)
+        response = conn.getresponse()
 
-	if response.status != 200:
-	    print(response.getheaders())
+        if response.status != 200:
+            print(response.getheaders())
             conn.close()
-	    raise RuntimeError("{0}: {1}".format(response.status,response.reason))
-	return response.read()
+            raise RuntimeError("{0}: {1}".format(response.status,response.reason))
+        return response.read()
+
 
-#test code
+# test code
 if __name__ == "__main__":
     client = MaryTTSClient()
     audio = client.generate_phonemes("test 1 2 3 4 5 6 7 8 9 10")
