Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 37c62af

Browse files
EmerickHrenekliment
authored andcommitted
Add Windows support (#258)
* more info on the Wiki (to be added later)
1 parent 47242ff commit 37c62af

File tree

9 files changed

+96
-21
lines changed

9 files changed

+96
-21
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
55

66
## [Unreleased]
77

8+
### Added
9+
- Windows support
10+
811
### Changed
912
- Switched from pyalsaaudio (ALSA) to pyaudio (PortAudio)
1013
- You might have to change the `input_device` in your config, but this name will stay forever (we are not planning any change).

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# AlexaPi (the new & awesome version) [![Gitter chat](https://badges.gitter.im/alexa-pi/Lobby.png)](https://gitter.im/alexa-pi/Lobby)
22

3-
This is a client for Amazon's Alexa service. It is intended and tested to run on a wide range of platforms, such as Raspberry Pi, Orange Pi, CHIP and ordinary Linux desktops.
3+
This is a client for Amazon's Alexa service. It is intended and tested to run on a wide range of platforms, such as Raspberry Pi, Orange Pi, CHIP and ordinary Linux or Windows desktops.
44

55
### Do you want to help out? Read the [Contribution Guide](CONTRIBUTING.md).
66

@@ -10,16 +10,16 @@ This is a client for Amazon's Alexa service. It is intended and tested to run on
1010

1111
You will need:
1212

13-
1. **A Linux box**
13+
1. **A Linux or Windows box**
1414
- a Raspberry Pi and an SD Card with a fresh install of Raspbian
1515
- or an Orange Pi with Armbian
16-
- or pretty much any up-to-date Linux system
16+
- or pretty much any up-to-date Linux/Windows system
1717
2. **Audio peripherals**
1818
- external speaker with 3.5mm Jack
1919
- USB Sound Dongle and microphone
20-
3. Other
21-
- (optional) (Raspberry Pi) a push button connected between GPIO 18 and GND (configurable)
22-
- (optional) (Raspberry Pi) a dual colour LED (or 2 single LEDs) connected to GPIO 24 & 25 (configurable)
20+
3. **Optional (only for Raspberry Pi)**
21+
- a push button connected between GPIO 18 and GND (configurable)
22+
- a dual colour LED (or 2 single LEDs) connected between GPIO 24 & 25 and GND (configurable)
2323

2424
## You wanna give it a try? Check out the [Installation Guide](https://github.com/alexa-pi/AlexaPi/wiki/Installation).
2525

src/alexapi/playback_handlers/vlchandler.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import threading
22
import logging
3+
import platform
34
import vlc
45
from .basehandler import BaseHandler, PlaybackAudioType
56

@@ -35,26 +36,31 @@ def on_setup(self):
3536

3637
parametersSpeech = parametersCommon
3738

38-
if self.__config['sound']['output']:
39-
parametersSpeech.append('--aout=' + self.__config['sound']['output'])
39+
if not platform.system() == 'Windows':
4040

41-
if self.__config['sound']['output_device']:
42-
parametersSpeech.append('--alsa-audio-device=' + self.__config['sound']['output_device'])
41+
if self.__config['sound']['output']:
42+
parametersSpeech.append('--aout=' + self.__config['sound']['output'])
43+
44+
if self.__config['sound']['output_device']:
45+
parametersSpeech.append('--alsa-audio-device=' + self.__config['sound']['output_device'])
4346

4447
self.vlc_instance = vlc.Instance(*parametersSpeech)
4548
self.player = self.vlc_instance.media_player_new()
4649

4750
self.media_vlc_instance = self.vlc_instance
4851
self.media_player = self.player
49-
if self.__config['sound']['media_output']:
50-
parametersMedia = parametersCommon
51-
parametersMedia.append('--aout=' + self.__config['sound']['media_output'])
5252

53-
if self.__config['sound']['media_output_device']:
54-
parametersMedia.append('--alsa-audio-device=' + self.__config['sound']['media_output_device'])
53+
if not platform.system() == 'Windows':
54+
55+
if self.__config['sound']['media_output']:
56+
parametersMedia = parametersCommon
57+
parametersMedia.append('--aout=' + self.__config['sound']['media_output'])
5558

56-
self.media_vlc_instance = vlc.Instance(*parametersMedia)
57-
self.media_player = self.media_vlc_instance.media_player_new()
59+
if self.__config['sound']['media_output_device']:
60+
parametersMedia.append('--alsa-audio-device=' + self.__config['sound']['media_output_device'])
61+
62+
self.media_vlc_instance = vlc.Instance(*parametersMedia)
63+
self.media_player = self.media_vlc_instance.media_player_new()
5864

5965
if self.__config['sound']['default_volume']:
6066
self.volume = self.__config['sound']['default_volume']
@@ -69,7 +75,11 @@ def on_play(self, item):
6975
vlcInstance = self.media_vlc_instance
7076
player = self.media_player
7177

72-
media = vlcInstance.media_new(item.url)
78+
url = item.url
79+
if platform.system() == 'Windows':
80+
url = item.url.replace("file://", "")
81+
82+
media = vlcInstance.media_new(url)
7383
player.set_media(media)
7484

7585
volume = self.volume

src/alexapi/triggers/pocketsphinxtrigger.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import threading
33
import logging
4+
import platform
45

56
from pocketsphinx import get_model_path
67
from pocketsphinx.pocketsphinx import Decoder
@@ -43,7 +44,12 @@ def setup(self):
4344

4445
# Hide the VERY verbose logging information when not in debug
4546
if logging.getLogger('alexapi').getEffectiveLevel() != logging.DEBUG:
46-
ps_config.set_string('-logfn', '/dev/null')
47+
48+
null_path = '/dev/null'
49+
if platform.system() == 'Windows':
50+
null_path = 'nul'
51+
52+
ps_config.set_string('-logfn', null_path)
4753

4854
# Process audio chunk by chunk. On keyword detected perform action and restart search
4955
self._decoder = Decoder(ps_config)

src/auth_web.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,5 @@ def code(self, var=None, **params): # pylint: disable=unused-argument
8383

8484
ip = [(s.connect(('8.8.8.8', 53)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1]
8585
print("Ready goto http://{}:5050 or http://localhost:5050 to begin the auth process".format(ip))
86-
print("(Press Ctrl-C to exit this script once authorization is complete)")
86+
print("(Press Ctrl-C (or close this window on Windows) to exit this script once authorization is complete)")
8787
cherrypy.quickstart(Start())

src/debug.bat

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
echo off
2+
title AlexaPi for Windows
3+
cls
4+
5+
python main.py -d
6+
7+
pause

src/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
requests>=2.13.0
22
CherryPy>=10.1.1
3-
git+https://github.com/oaubert/python-vlc.git#egg=python-vlc
3+
python-vlc
44
pyaudio>=0.2.10
55
webrtcvad>=2.0.10
66
pyyaml

src/scripts/setup.bat

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
echo off
2+
title AlexaPi for Windows Installation
3+
cls
4+
5+
SET mypath=%~dp0
6+
SET apath=%mypath:~0,-8%
7+
SET path=%path%;%mypath%\swigwin-AlexaPi
8+
9+
echo -------------------------------------------
10+
echo Welcome in AlexaPi installation for Windows
11+
echo -------------------------------------------
12+
13+
echo Installing dependencies:
14+
15+
python -m pip install -r "%apath%requirements.txt"
16+
17+
pause
18+
cls
19+
20+
cd %apath%
21+
22+
copy config.template.yaml config.yaml
23+
24+
echo ######################################################################################################
25+
echo IMPORTANT NOTICE:
26+
echo You HAVE TO set up Amazon keys in the config.yaml file now
27+
echo ######################################################################################################
28+
pause
29+
30+
start python.exe auth_web.py
31+
32+
echo =====
33+
echo Done!
34+
echo =====
35+
pause
36+
cls
37+
echo ######################################################################################################
38+
echo IMPORTANT NOTICE:
39+
echo You may HAVE TO set up your system audio.
40+
echo See on our wiki
41+
echo ######################################################################################################
42+
pause

src/start.bat

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
echo off
2+
title AlexaPi for Windows
3+
cls
4+
5+
python main.py
6+
7+
pause

0 commit comments

Comments
 (0)