From 7a6f878ed4fe3b5427d35c5c0c73c6e5c757b503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beg=C3=BCm=20Erciyas?= Date: Mon, 28 Jan 2019 17:27:38 +0100 Subject: [PATCH] Fixes for mac --- hugvey/client.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/hugvey/client.py b/hugvey/client.py index 8ba7f05..01d5f62 100644 --- a/hugvey/client.py +++ b/hugvey/client.py @@ -7,10 +7,14 @@ import socket import threading import time import yaml -import alsaaudio import zmq from zmq.asyncio import Context +try: + import alsaaudio +except ImportError: + print("No volume settings available") + from .communication import zmqReceive, zmqSend, getTopic import subprocess @@ -239,8 +243,14 @@ class Hugvey(object): def getId(self) -> int: """Get Hugvey ID from hostname""" - h = socket.gethostname() - return int(re.findall('\d+', h )[0]) + try: + h = socket.gethostname() + id = int(re.findall('\d+', h )[0]) + except Exception: + logger.critical("No automatic ID, fall back to 1") + id = 1 + + return id def loadConfig(self, filename): with open(filename, 'r') as fp: @@ -253,7 +263,7 @@ class Hugvey(object): def start(self): loop = asyncio.get_event_loop() - if self.config['voice']['play_device']: + if self.config['voice']['play_device'] and 'alsaaudio' in sys.modules: alsaaudio.Mixer(self.config['voice']['play_device']).setvolume(self.config['voice']['play_volume']) self.voice_server = VoiceServer(