#linux [RSS]
#all #tech #art #personal #media

10.04.2022

Speech to text diary scripts

#tech #linux

First of all, this blog post is about a somewhat specific problem. Despite this, I think it is quite useful to most readers looking for some Linux knowledge as the tools I used are very general. Let's start with the explanation of

The problem

Sometimes I have good ideas when I'm outside. Sometimes I really wanna preserve these ideas, but it's very inconvenient to use phone keyboards, especially on the move. One solution is recording my voice. But then, I would want to transfer those recordings to my computer for future reference. But what if I also want to read the text version of those voice recordings? Let's handle these problems one at a time.

Syncing files

Syncthing

Syncthing is an open source cross-platform program that can sync folders accross multiple devices. It's perfect for this problem, as it allows for P2P syncing (for example from a phone to a computer).
It's very easy to set up aswell, you download it on both devices, open a browser (Synthing has a web frontend) tab on 127.0.0.1:8384 and scan the ID QR with your phones camera. Then share whatever is the folder that has your audio recordings.

If your init system is systemd, to start synthing (and enable autostart at boot) you can run (where USER is your linux user): systemctl enable syncthing@USER.service --now Synthing has configuration options for encryption and file filtering. If you want more robust syncing, you could also host a Syncthing instance on a server.

Speech to text

To convert my speech to text I use the SpeechRecognition python package: pip install SpeechRecognition It supports many speech recognition options, including offline ones. It's also really easy to use, check my script.

Options (present in my script as comments):

There are also other online and offline options. (SpeechRecognition documentation)

Storing recorings in notes

Vimwiki

I use vimwiki vimwiki (a (neo)vim plugin) that makes managing markdown files in a wiki-like manner extremely easy. Vimwiki also has a diary option. To store the recording path and text in my notes, I wrote a few scripts.

The speech-to-diary.sh script calls the speech recognition script on a selected file, appends transcription to a vimwiki diary and (optionally) moves the voice recording to the vimwiki folder. it has a bunch of flags, you can get a help message by running: ./speech-to-diary.sh -h

The text that it puts looks like this: 20220328_162342.m4a 16:24:05
Whatever speech recognition returned
/home/tea/vimwiki/diary/resources/20220328_162342.wav
I have a vim shortcut that plays an audio file under the cursor so that I can also listen to it if the transcription is not accurate enough.

If you don't use vim or vimwiki, you can just change the last line of the script to save the text to a file of your choosing.

Tying it all together

Actual Linux knowledge

Now, we need a way to react to new files appearing in the syncing directory. For that, we can use the linux inotify interface, that waits for changes in files. For syncthing, the following command works: inotifywait -c -r -m -e attrib $PATH_TO_WATCH You can also see it used in a script. Be sure to read the readme on the repo for some additional information on setting up a systemd service (if you don't know how).

Now, if you autostart syncthing and the watchscript at system boot, it will process all new audio files.

13.03.2022

Simple video editing with MPV

#tech #linux

MPV is one of my favorite open source projects. It's a simple-looking video player with an enormous amount of features while also being highly extensible through the lua programming language.

MPV-splice Script

MPV-splice is a script that allows you to use MPV as a video editor. You set the start and end timings for fragments, and then the script cuts the video and concatenates the fragments.

I made a fork of it to extend it's abilities.

Another useful script I forked is 8mb, which compresses your video to 8mb, changing it's FPS and resolution to appropriate values.

20.02.2022

Music Playing: Local & Remote

#tech #linux

The most basic way to play music is using some website. Most people prefer Spotify, but I never liked it.

For the longest time I've been using Soundcloud, it has most music I like, especially the quirky electronic type. It also allows you to upload songs without any additional setup. But, of course, there are songs that are not on there. The worst part is that some more main-stream artists have their songs region-locked or only available with soundcloud premium.

Local Music Library

A year back I decided to begin storing my music locally. This approach ensures that I have access to all my favorite music, in best quality, offline, forever.

It is honestly really freeing and opened a bunch of possibilities for me.

DeaDBeeF Music Player

I first settled on DeaDBeeF, as it's highly customisable, extensible and actively developed.

Configuring takes some time to get used to. You have to enable 'design mode' in the 'View' submenu to start adding and removing panes. It allows you to use a lot of GTK3 (UI library) widgets to structure your window however you like. You can find my config in the GitHub repo linked below.

I especially like the visualization plugins that I found. On Arch-based systems it is extremely easy to install plugins: yay -S deadbeef-plugin-spectrogram-gtk3-git \
deadbeef-plugin-musical-spectrum-gtk3-git \
deadbeef-plugin-rating \
deadbeef-plugin-waveform-gtk3-git
Some plugins are configured through settings, others through the right-click menu.

There are 2 main problems with DeaDBeeF for me:

Both of these features are in plans so at some point in the future I hope we'll get them.

MPD Music Server

Recently I started using MPD. It's a bit technical.

It might sound scary at first but all you need to do to set it up is create 1 config file and run the server. There are a lot of clients that allow you to connect to an MPD server with relatively conventional interfaces. I am currently using Cantata, as it's the most feature rich one I could find.

The great thing about MPD is that you can connect as many clients as you want and they all will be synchronized with each other. There are clients for scrobbling your music to last.fm (with mpdas), setting your discord 'rich presense' and controlling playback with media keys or a notification (with mpdris2). It's the most modular music playing experience and I love it. My config looks like this: music_directory "~/Music"
db_file "~/.config/mpd/database"
playlist_directory "~/.config/mpd/playlists"
sticker_file "~/.config/mpd/sticker.sql"
log_file "syslog"
auto_update "yes"
restore_paused "yes"

audio_output {
type "pulse"
name "pulse audio"
}

audio_output {
type "fifo"
name "my_fifo"
path "/tmp/mpd.fifo"
format "22050:16:2"
}
'sticker_file' allows for custom music ratings (supported by Cantata), 'fifo' audio output allows for latency-less audio visualization with Glava.

To install everything I mentioned on Arch you would run: yay -S mpd mpd-discord-rpc-git mpdas mpdris2 cantata

Remote Music Library

But what if I want to play my music on a device where I don't have my audio library?

MPD Does it All

You can create an http output by putting the following lines in your config: audio_output {
type "httpd"
name "My HTTP Stream"
encoder "lame"
port "8000"
bitrate "192"
format "44100:16:1"
max_clients "0" # 0=no limit
}
I host an MPD instance on my server and can control playback with any client. On my phone I use MPDroid (which can also stream the aduio). To stream audio on desktop you have to connect to the specified port through a music player that can play http streams, like mpv, or a web browser. MPD clients, such as Cantata, can also play http audio streams. The delay is a little annoying. There is a setup that allows for 0 delay playback ( with local mpd using a remote music library) I saw here: www.joram.io/blog/android-streaming-mpd/

But I want my recommendations!

MPD :)

There is a client that automatically queues new songs based on last.fm recommendations.