Giter VIP home page Giter VIP logo

lua-libsox's Introduction

Lua-libsox: Lua bindings for libSoX

Lua-libsox is a Lua binding library for the Swiss Army knife of sound processing programs (SoX).

It runs on GNU/Linux and requires Lua (>=5.1) and SoX (>=14.4.2).

Authored by: Díaz Devera Víctor Diex Gamar (Máster Vitronic)

Lua logo

License

MIT license . See LICENSE.

Documentation

See the Reference Manual.

Motivation:

I was looking for a long time without success, to manipulate and play audio files from Lua, unfortunately these features were not available until now, certainly there are other bindings (like SDL2 or ao) for audio support, but none comes close to the power of SoX to encode/decode, play and add effects to audio files.

Getting and installing

$ git clone https://gitlab.com/vitronic/lua-libsox.git
$ cd lua-libsox
lua-libsox$ make
lua-libsox$ make install # or 'sudo make install' (Ubuntu)

Example

-- Script: player.lua

local libsox = require("libsox")
local sox    = libsox:new()

--All libSoX applications must start by initialising the SoX library
if not sox:init() then
	error("Failed to initialize SoX")
end

--Open audiofile
local input  = sox:open_read(arg[1])
if not input then
	error("Failed to open file")
end
local signal = sox:signal(input)

--Open soundcard
--Change "alsa" in this line to use an alternative audio device driver:
local output = sox:open_write('default',signal, 'alsa') --Or pulseaudio Or ao etc
if not output then
	error("Failed to open output")
end

--a way to open the sound card with custom parameters
--local output = sox:open_write('default',{
	--rate=8000,channels=1,precision=32
--},'alsa')

--Or if you prefer, store all this to another file
--local output = sox:open_write('/tmp/coso.mp3',input, 'mp3')

--The buffer size
local buf_sz = 8192*2
--initialize the buffer
local buffer = sox:buffer(buf_sz)

--The main Loop
while true do
	local sz = sox:read(input,buffer,buf_sz)
	if sz == 0 then break end
	sox:write(output, buffer, sz)
end

--All done; tidy up:
sox:close(input)
sox:close(output)
sox:quit()

The script can be executed at the shell prompt with the standard Lua interpreter:

$ lua player.lua sound.ogg

Other examples can be found in the examples/ directory contained in the release package

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

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.