stsaz / fmedia

fast audio player/recorder/converter
BSD 2-Clause "Simplified" License
216 stars 21 forks source link

How do I terminate the process correctly to prevent invalid wav header? #51

Closed hced closed 4 years ago

hced commented 4 years ago

I've made a working script in AutoHotkey to toggle recording sound via fmedia.exe. After killing fmedia.exe and opening my recording in WaveLab, it says the wav header is invalid. This won't happen if I run fmedia in a console and exit with CTRL-C. (The same broken wav header occurs in ffmpeg, if I kill the process. However, if ffmpeg is quit by CTRL-C it says "Exiting normally, received signal 2", which seems like a good clue to my issue. Basically, I want my command to be run hidden (no console) and preferably I want to programmatically send fmedia a signal to stop what it's doing and exit, with a good interrupt signal like SIGINT.

Here's my draft AutoHotkey script that toggles recording to a date-formated file:

F1::
t_SoundRec := !t_SoundRec
if (t_SoundRec = 1)
{
    ; Start recording
    FormatTime, CurrentDateTime,, yyyyMMddHHmmss
    Run, C:\Portable\fmedia\fmedia.exe --record -o D:\Dropbox\Audio\REC\%CurrentDateTime%.wav --format=int16 --channels=stereo --rate=44100, , Hide
    return
}
else
{
    ; Stop recording
    Process, Close, fmedia.exe
    return
}
return
stsaz commented 4 years ago

Hi! You need to run fmedia with --globcmd=listen and then stop with fmedia --globcmd=stop, as described here: https://stsaz.github.io/fmedia/recording/#globcmd