Giter Site home page Giter Site logo

blumamir / wavplayeralsa Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 1.0 1.17 MB

linux wav files audio player intended for accurate position tracking

License: MIT License

C++ 79.17% CMake 1.44% Python 3.98% HTML 1.38% JavaScript 1.95% TypeScript 11.09% CSS 0.07% Dockerfile 0.92%
alsa-pcm cpp11 audio-player linux-app

wavplayeralsa's Introduction

wavplayeralsa

Installation process (tested on Raspbian and Ubuntu)

  1. Install Raspbian https://www.raspberrypi.org/documentation/installation/installing-images/
  2. Install boost, sndfile and libsound libs
  sudo apt-get install libsndfile1-dev libasound2-dev libboost-all-dev
  1. Clone the wavplayeralsa project and compile it
  git clone https://github.com/BlumAmir/wavplayeralsa.git
  cd wavplayeralsa/
  mkdir bin
  cd bin
  cmake ..
  make
  1. Create a configuration file for the player

Player description

  1. The player is a wav files audio player intended for accurate position tracking.
  2. Control over the player is done over HTTP, selecting the currently playing file and starting position.
  3. The player publishes the currently playing file and accurate start time position in milliseconds since epoch over web socket. Client can calculate precise offset in song by using it's local clock and the start time information.

Usage

The executable supports a few commandline arguments, for a list of available options use ./wavplayeralsa -h

To play a specific file use ./wavplayeralsa -f <file_name>.wav

logging

Player write log messages to console. By setting log_dir command line argument to an existing directory, player will create a unique log file for each run.

Control interface

Controling the player is done via HTTP interface. Player's command line option 'http_listen_port' is used to set the port on which the player listens for control commands and queries.

To play an audio file, send a json to uri http://PLAYE_IP:HTTP_LISTEN_PORT/api/current-song in the following format: { "file_id": "path/from/wav/dir/<file_name>.wav", "start_offset_ms":0 } example with curl:

curl -X PUT -H "Content-Type: application/json" -d "{\"file_id\": \"<file_name>.wav\", \"start_offset_ms\":0}" "http://127.0.0.1:8080/api/current-song"

start_offset_ms can be negative, in which case song will start to play in the future.

To stop an audio file which is currently playing, send a json to uri http://YOUR_IP:HTTP_LISTEN_PORT/api/current-song with empty or missing 'file_id': { "file_id": "" } or {} example with curl :

curl -X PUT -H "Content-Type: application/json" -d "{}" "http://127.0.0.1:8080/api/current-song"

Position report interface

Player's command line option 'ws_listen_port' is used to set the port on which the player listens for web sockets client who wish to receive push notifications on events:

When a new audio file is played, or when the current audio position is changed externally: {"file_id":"<file_name>.wav","song_is_playing":true,"speed":1.0,"start_time_millis_since_epoch":1551335294511}

When a stop is performed via control interface, or when audio reach end of file: {"song_is_playing":false}

start_time_millis_since_epoch is the audio's file start time (position 0) in milliseconds, since UNIX Epoch time (00:00:00 Thursday, 1 January 1970, UTC). Client can calculate the file's audio position at any givin time, using it's local clock, which should be synchronized to the player's clock. This enable clients to act upon precise and continuous audio position, which does not dependent on network latency and update rate. Any offset in clock synchronization (between client's and player's os) will be carried to audio position calculation, thus user should assure such offset is minimal (using NTP for example, or running client on same machine as player).

Docker

You can run the player as a docker.

Build: docker build -t wavplayeralsa .

Run: docker run -p 8080:80 -v ${MusicDirectory}:/wav_files --device /dev/snd --name wavplayeralsa wavplayeralsa

wavplayeralsa's People

Contributors

blumamir avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

eranws

wavplayeralsa's Issues

why I don't play .wav file?

โ‡’  ./wavplay -f  wav-pcm32.wav
[2020-12-01 15:32:30.341] [root] [info] hello wavplayeralsa. logger initialized
[2020-12-01 15:32:30.341] [root] [info] pid of player: 3606
[2020-12-01 15:32:30.341] [root] [info] Configuration:
player: wav_dir='/home/value/Documents/proj/audio' initial file to play: 'wav-pcm32.wav'
web sockets: listen_port='9002'
http: listen_port='8080'
mqtt: disabled
log file: not saving log to file, as none is configured
audio device: 'default'
[2020-12-01 15:32:30.342] [root] [info] Generated uuid for this player run: e4c7caac-1c5a-45fc-bf44-802c033ddf6f
[2020-12-01 15:32:30.344] [root] [critical] failed initialization, unable to start player. web socket server listen on port 9002 failed, probably not able to bind to port. error msg: Underlying Transport Error

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.