Gone look at making at making simple standalone Sound-player that can play most format eg
Gone make it for Windows and Linux.
The goal is one standalone file(Windows:
Install
Tool for this pipenv, pyinstaller, pyglet and Click.
Start with pipenv which is great for keeping track of dependencies,it's a marriage of
See all dependencies is installed also newer
which could be used i doing this without using virtual environment.
Code
Pyglet for playing which is using AVbin
even if i try to make clear so do not Pyinstaller find these files,so add it manually.
Click is great command line tool,
Build
Build with Pyinstaller:
Command for Windows:
Command for Linux:
There is a little difference
Every time Pyinstaller run a .spec file is generated,in this case
This file can be edit to add more stuff,then run like this.
Usage
It's a very simple player,eg place
and it work from anywhere in
Example:
Take away
A look a pipenv a cool that keep track of dependencies and make pip and virtual environment work with one command.
Pyinstaller a good tool for bundle all dependencies is single single package.
Click for creating beautiful command line interfaces,in my option the best of the bunch.
.mp3
.Gone make it for Windows and Linux.
The goal is one standalone file(Windows:
play.exe
and Linux:play
) this file can be moved to any OS and just work.Install
Tool for this pipenv, pyinstaller, pyglet and Click.
Start with pipenv which is great for keeping track of dependencies,it's a marriage of
pip
and virtualenv
. # Install pipenv pip install -U pipenv # Now pipenv in a folder eg (mkdir)sound_env pipenv install pyinstaller, pyglet, click # Activate sound_env folder pipenv shellTake a look at dependencies in Windows and Linux.
pipenv graph
See all dependencies is installed also newer
pypiwin32
and not older win32api
,which could be used i doing this without using virtual environment.
Code
import pyglet import click from msvcrt import getch pyglet.lib.load_library('avbin.dll') pyglet.have_avbin=True @click.command() @click.argument('file', type=click.Path(exists=True), metavar='<file>') def play(file): ''' Play sound file from command line Supported format: AU,MP2,MP3,OGG/Vorbis,WAV,WMA \b Example: play song.mp3 # File with space use quote. play "Clean Bandit.mp3" <Space> quit the song ''' music = pyglet.media.load(file) music.play() while True: key = ord(getch()) # 32 use space to quit if key == 32: break pyglet.app.run() if __name__ == '__main__': play()Test code:
E:\sound_env λ which python /c/Users/Tom/.virtualenvs/sound_env-zFUYyERb/Scripts/python E:\sound_env λ python play.py "Clean Bandit.mp3" E:\sound_env λLinux:
Pyglet for playing which is using AVbin
avbin.dll
(windows) and libavbin.so.10
(Linux),even if i try to make clear so do not Pyinstaller find these files,so add it manually.
Click is great command line tool,
type=click.Path(exists=True)
will do error checking so we don't.metavar='<file>'
will use docstring of function when do play --help
Build
Build with Pyinstaller:
Command for Windows:
pyinstaller --onefile --console --icon=sound.ico --add-data avbin.dll;. play.py
Command for Linux:
pyinstaller --onefile --console --icon=sound.ico --add-data libavbin.so.10:. play.py
There is a little difference
;.
Win and Linux :.
..
- Destination path of dll in .exe or play file(Linux).Every time Pyinstaller run a .spec file is generated,in this case
play.spec
This file can be edit to add more stuff,then run like this.
pyinstaller --clean play.spec
Usage
It's a very simple player,eg place
play.exe
it environment variable Path(Windows),and it work from anywhere in
cmd
.Example:
# Excutebale mint@mint ~/sound_env/dist $ chmod +x play # Use mint@mint ~/sound_env/dist $ ./play --help Usage: play [OPTIONS] <file> Play sound file from command line Supported format: AU,MP2,MP3,OGG/Vorbis,WAV,WMA Example: play song.mp3 # File with space use quote. play "Clean Bandit.mp3" <Ctrl+c> quit the song # Play Song Linux mint@mint ~/sound_env/dist $ ./play faded.mp3 # Play Song windows C:\1>play "Clean Bandit.mp3"Look with icon Windows:
Take away
A look a pipenv a cool that keep track of dependencies and make pip and virtual environment work with one command.
Pyinstaller a good tool for bundle all dependencies is single single package.
Click for creating beautiful command line interfaces,in my option the best of the bunch.