From d459acd60966f5878c75af5da55876412421e7cc Mon Sep 17 00:00:00 2001 From: Yihui Xiong Date: Wed, 28 Mar 2018 15:18:24 +0800 Subject: [PATCH] reorganize player, prefer mpg123 to play local mp3 --- avs/interface/alerts.py | 6 +++++- avs/interface/audio_player.py | 1 + avs/interface/speech_synthesizer.py | 6 +++++- avs/{player.py => player/__init__.py} | 15 +++++++++++---- avs/{ => player}/gstreamer_player.py | 0 avs/{ => player}/mpg123_player.py | 2 ++ avs/{ => player}/mpv_player.py | 3 +++ avs/{ => player}/single_gstreamer_player.py | 0 setup.py | 12 ++++++------ 9 files changed, 33 insertions(+), 12 deletions(-) rename avs/{player.py => player/__init__.py} (50%) rename avs/{ => player}/gstreamer_player.py (100%) rename avs/{ => player}/mpg123_player.py (95%) rename avs/{ => player}/mpv_player.py (95%) rename avs/{ => player}/single_gstreamer_player.py (100%) diff --git a/avs/interface/alerts.py b/avs/interface/alerts.py index fc5ecf9..5796b84 100644 --- a/avs/interface/alerts.py +++ b/avs/interface/alerts.py @@ -9,7 +9,11 @@ from threading import Timer, Event import uuid -from avs.player import Player +# prefer mpg123 player as it is more responsive than mpv and gstreamer +if os.system('which mpg123') == 0: + from avs.player.mpg123_player import Player +else: + from avs.player import Player class Alerts(object): diff --git a/avs/interface/audio_player.py b/avs/interface/audio_player.py index 7fcd48b..a4d19f3 100644 --- a/avs/interface/audio_player.py +++ b/avs/interface/audio_player.py @@ -176,6 +176,7 @@ def PlaybackStutterFinished(self): def PlaybackFinished(self): self.state = 'FINISHED' + logger.info('playback is finished') event = { "header": { diff --git a/avs/interface/speech_synthesizer.py b/avs/interface/speech_synthesizer.py index 204b3ac..4ddd610 100644 --- a/avs/interface/speech_synthesizer.py +++ b/avs/interface/speech_synthesizer.py @@ -6,7 +6,11 @@ import hashlib import logging -from avs.player import Player +# prefer mpg123 player as it is more responsive than mpv and gstreamer +if os.system('which mpg123') == 0: + from avs.player.mpg123_player import Player +else: + from avs.player import Player logger = logging.getLogger('SpeechSynthesizer') diff --git a/avs/player.py b/avs/player/__init__.py similarity index 50% rename from avs/player.py rename to avs/player/__init__.py index 4a278b6..a744d60 100644 --- a/avs/player.py +++ b/avs/player/__init__.py @@ -1,6 +1,10 @@ # -*- coding: utf-8 -*- -"""Player""" +"""Player +support mpv, mpg123 and gstreamer 1.0 +It prefers mpv if it is available, otherwise use gstreamer 1.0 +We can specify a player using environment variable PLAYER (mpv, mpg123, gstreamer, single_gstreamer) +""" import os @@ -12,11 +16,14 @@ from mpg123_player import Player elif player_option.find('single') >= 0: from single_gstreamer_player import Player -else: +elif player_option.find('gstreamer') >= 0: from gstreamer_player import Player +else: + if os.system('which mpv') == 0: + from mpv_player import Player + else: + from gstreamer_player import Player __all__ = ['Player'] - - diff --git a/avs/gstreamer_player.py b/avs/player/gstreamer_player.py similarity index 100% rename from avs/gstreamer_player.py rename to avs/player/gstreamer_player.py diff --git a/avs/mpg123_player.py b/avs/player/mpg123_player.py similarity index 95% rename from avs/mpg123_player.py rename to avs/player/mpg123_player.py index 8890a57..a834410 100644 --- a/avs/mpg123_player.py +++ b/avs/player/mpg123_player.py @@ -7,6 +7,8 @@ import threading import subprocess +if os.system('which mpg123') != 0: + ImportError('mpg123 not found, install it first') class Player(object): def __init__(self): diff --git a/avs/mpv_player.py b/avs/player/mpv_player.py similarity index 95% rename from avs/mpv_player.py rename to avs/player/mpv_player.py index 9b00f29..56a4cd9 100644 --- a/avs/mpv_player.py +++ b/avs/player/mpv_player.py @@ -7,6 +7,9 @@ import threading import subprocess +if os.system('which mpv') != 0: + raise ImportError('mpv not found, install it first') + class Player(object): def __init__(self): diff --git a/avs/single_gstreamer_player.py b/avs/player/single_gstreamer_player.py similarity index 100% rename from avs/single_gstreamer_player.py rename to avs/player/single_gstreamer_player.py diff --git a/setup.py b/setup.py index b046e54..ee8b1d5 100644 --- a/setup.py +++ b/setup.py @@ -5,11 +5,10 @@ from setuptools import setup, find_packages -with open('README.rst') as readme_file: - readme = readme_file.read() -with open('HISTORY.rst') as history_file: - history = history_file.read() +with open('README.md') as f: + long_description = f.read() + requirements = [ 'click', @@ -29,9 +28,10 @@ setup( name='avs', - version='0.1.1', + version='0.2.0', description="Python implementation of Alexa Voice Service App", - long_description=readme + '\n\n' + history, + long_description=long_description, + long_description_content_type='text/markdown', author="Yihui Xiong", author_email='yihui.xiong@hotmail.com', url='https://github.com/respeaker/avs',