Cron job for starting/stopping recorder

I wonder if parecord would suffice?

2 Likes

Thanks @nephros . I’m not familiar with it, but a quick look at parecord -h, and it appears from the available arguments, that it should do the trick. I will take a further look at it.

Hi @nephros . I got time to try out parecord this morning. It looks like it could do the job. However, there are a few caveats:

  • It appears there is a long-outstanding bug with recording in OGG/OGA or FLAC audio formats. WAV is not feasible for long duration recordings. Any recommendations for high-quality, high compression audio formats that do work?
  • I don’t see a parameter to stop the recording. Would there be a more elegant way of handling this, other than pkill parecord?
1 Like

Did you compile it or find packages that work on SFOS? I’d take a look at the bug.

By default, it does not work on other Linux distributions nor on Sailfish. Since there is no proposed fix for this, a kernel compile would not resolve the issue.
If you know of packages that solve the problem, please enlighten us.

As I noted above, I have functional recording (c++, Videoworks) which I’m working on incorporating in Audioworks hence have another solution in mind.

Regardless, looking at the reports you linked, I’m not inclined to believe it’s been exhaustively tested :slight_smile: Why do you conclude it’s a kernel module problem?
The last viewable bug report says it is:

pa_sndfile_format_from_string()

Which is not in a kernel module.

I may take a crack at it, but will probably build my own solution.

parecord -d jack_out.monitor -r > test.mp3

Works fine. So, just how did you test parecord?

EDIT: so does ogg:

Linux XX 5.15.0-56-lowlatency #62-Ubuntu SMP PREEMPT Wed Nov 23 09:50:07 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

I guess it should also be possible to plug the raw PCM stream into a gstreamer pipe.

Might even get hardware encoding this way.

for me this works:

parec ~defaultuser/SoundRec/$(date +"%Y%m%d-%H%M%S").audio

The file is raw data and I can convert it to whatever using audacity on my pc (Import → Raw data). It creates huge files so watch out. I think I tried the on-the-fly mp3 conversion but the battery drainage was alot for long recordings. If you want a script that detects if parec runs and kills it but if it doesn’t run it start recording, and also changes the microphone sensitivity here it is:

   #!/bin/sh

   if [ -n "$(ps -e | grep parec)" ]; then
     killall parec;
     pacmd set-source-volume source.droid 65536;
     exit 0;
   fi

   pacmd set-source-volume source.droid 229376
   parec ~defaultuser/SoundRec/$(date +"%Y%m%d-%H%M%S").audio

Change the ~defaultuser / directory accordingly.

Reference source: Running shell script from *.desktop file - together.jolla.com

2 Likes

GNU coreutils has timeout which can kill a process after a defined time.

Not installed per default (package gnu-coreutils). BUT: installing this might break some scripts which expect the busybox versions of some of those tools.

1 Like

This approach works for me too, at least on the Volla22…

I checked the sink names first:

pactl list | grep monitor
Monitor Source: sink.primary_output.monitor

to just capture all output (without adjusting the volume).
parecord -d sink.primary_output.monitor -r > (date +"%Y%m%d-%H%M%S").mp3

This approach works for me on the Volla22 also directly to mp3/ogg and so on.
EDIT: SIGKILL / TERM etc all seem to be a fine way to shut down parecord.

1 Like

parecord -d source.droid --file-format=oga test.oga

Is the on-the-fly mp3 conversion some other application you refer to or that within parecord?
I can directly record and output to .mp3 (but wasn’t aware of battery drainage issues), but was looking for an audio file format that has an improved audio quality for the compression it offers - such as OGG/OGA, or FLAC with it being lossless.

As you pointed out, raw audio recording is not suitable as this is for long-duration recording and disk space issues would be a frequent frustration.

Did that work?

Just try recording for a set period of time with flac as the format (you don’t have to specify format, just file suffix) and see if the size will become an issue. Otherwise, use ogg.

Does what work? MP3 recording works, but is not what I was looking for.

FLAC and OGG/OGA recording does not work, with or without the --file-format parameter. The error is what was specified in the reported bug: Failed to open audio file

worked just now. of course, that captures ALL sound including the mic over whatever is coming on other channels :wink: It’s a poor man’s chorus effect.

.ogg (not oga) also works.

EDIT: I’m on crack. I’ve got redirects in my commands which shouldn’t be there. What DID work was

parecord -d sink.primary_output.monitor -r thing.mp3

EDIT: which is not mp3

[defaultuser@VollaPhone ~]$ file thing.mp3
thing.mp3: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, stereo 44100 Hz

Sorry about the noise. I’ll go find an encoder method (probably pipe to ffmpeg ).

Sorry about the confusion. This works, but requires installing ffmpeg:

parecord -d sink.primary_output.monitor -r --raw --passthrough | ffmpeg -f s16le -i - test.ogg

It just does raw passthrough of s16le to ffmpeg which is, in this case without options, just doing basic default encoding. When I have some time I’ll send on the correct 2 channel encoding options.

EDIT: input correctly specified with:

ffmpeg -f s16le -ac 2 -ar 48000 -i - test.ogg

ac: number of channels, ar: rate.

1 Like

I was wondering if you had any examples in mind? I’m looking into gstreamer (which i haven’t used in many years) since jolla supplies : gstreamer1.0-libav … any tips would be appreciated or just tell me RTFM :slight_smile:

EDIT: ah, wthell, I just did the reading:

Ok, this is a primary monitor output recording using gstreamer. You need to install the tools:

zypper install gstreamer1.0-tools
gst-launch-1.0 pulsesrc ! audioconvert ! vorbisenc ! oggmux ! filesink location=blah.ogg

That works.

1 Like

Good you figured out, I couldn’t have helped really.

I just remembered there was a thread about hw encoding and such pipelines were mentioned.

Yeah, but you got me thinking about it! I did some gstreamer programming (c++) about 10 years ago. So I’ve forgotten everything :slight_smile: But we actually have a lot there. I can replace a bunch of ‘ffmpeg’ binary calls with gstreamer. It’s still ‘work’ but all the libav/ffmpeg stuff is available on SFOS.

The hack with gst-launch-1.0 is cool. though. You can do a LOT of pipeline work with it without programming. I might write a gui wrapper app :slight_smile: