tSIP: compressing records using Lua and opusenc.exe

OBSOLETE: since version 0.2.09 recording as Opus/OGG is directly supported in tSIP, without the need to use scripting and external tools.

tSIP 0.01.63 supports recording only to uncompressed wave files - 2 bytes per sample, sampling rate depending on codec using during the call. This would result in best possible quality, perhaps is worth more than compressed data from legal point of view but may take lot of disk space. For widely used G.711a/u this would result in 16kB/s (or 128kbps) being written to disk. As calls may be also recorded in stereo (each side as separate channel) this might get doubled and with 16kHz codec (e.g. G.722) doubled again. For L16/48000 this would increase again three times. Compressing records using external tool after each record is created seems to be easy way to reduce file sizes and Opus/OGG seems to be quite flexible, handling both narrow- and wideband calls. Files created by opusenc.exe (.opus, Opus codec in OGG container) are supported by Foobar2000.

To avoid waiting for compression to complete, small utility, OpusEncLauncher.exe is used. It should be placed along with opusenc.exe in application directory. After starting, launcher would start encoding, wait for it to finish, read status and if it succeeded - delete original (wav) file.

Compression parameters (bitrate and other options as supported by opusenc.exe) can be changed by editing config file - OpusEncLauncher.json.

Script for "on call state" event:

call_state = GetCallState()

if call_state == 0 then -- CALL_STATE_CLOSED
	local fileName = GetRecordFile()
	if fileName ~= "" then
		print(string.format("Compressing %s\n", fileName))
		local params = fileName
		local filename = GetExeName()
		local index = string.find(filename:reverse(), "\\")
		local dir = string.sub(filename, 1, -index)
		local exe = dir .. "OpusEncLauncher.exe"    
		-- OpusEncLauncher would start opusenc and if 
		-- compression would succeed - delete source file   
		ShellExecute("open", exe, params, nil, 1)

Source code for OpusEncLauncher: OpusEncLauncher_1_0_0_src.zip.

OpusEncLauncher.exe + opusenc.exe: OpusEncLauncher_1_0_0_bin.zip. Binary for opusenc.exe comes from https://github.com/Chocobo1/opus-tools_win32-build/.

Back to howto list.

 "Cookie monsters": 7741441    Parse time: 0.000 s