Blog post: Audible Feedback
Tags: audio, alert, docker, interface
Published: 2018-08-26 10:43:01

---
title: Blog post: Audible Feedback
published: true
tags: audio,alert,docker,interface
canonical_url: https://lastmover.wordpress.com/2018/08/26/audible-feedback/
---

A long time ago I watched a TV show, which was taking place in a South Korean shipyard. I cannot remember whether it was one of these mega-structure programmes or something similar, but I do remember when the huge cranes in the shipyard where moving they were playing tunes instead of alarms, like when trucks are driving in reverse or similar. I have thought a lot about the rationale behind this and has come to the conclusion, that it was important to create a distinct sound with would stand our from all of the other noise in the shipyard.

Today I work at a workstation with 3 screens, I have a plethora of different windows, editors, terminals, database interfaces, email client etc.

I am using headphones with noise cancellation since I am seated in an open office space and I want to guard my attention span. I listen to music, primarily electronica, without lyrics, since I have discovered that I am more easily distracted, if I listen to tunes with lyrics (_If somebody can explain this phenomenon, I am all ears_). Some [recommendations](https://medium.com/@jonasbn/there-are-some-nice-streams-on-soma-fm-40d36d631324) for “[Background Music for Coding](https://medium.com/level-up-web/youtube-background-music-for-coding-99b592a74dc8)” in addition to: [musicforprograming.net](http://musicforprogramming.net/), which I listen to regularly together with some cool playlists on Spotify).

When coding my eyes are occupied, with source code, script output, compiler/interpreter/toolchain feedback.

At the same time a have long a short processes, running in the front or in the background. These are often jobs, such as:

- Test runs
- **Docker** builds
- Test database builds

So when I discovered [@tara-gibbs](https://gist.github.com/tara-gibbs) `hey` utility ([Gist: hey](https://gist.github.com/tara-gibbs/cf91bc86c580f244de0ae9f5978edaac)) I was thrilled and I put it to use, after some time I decided to extend my use of audible feedback.

```
#!/bin/bash # 

REF: https://gist.github.com/tara-gibbs/cf91bc86c580f244de0ae9f5978edaac 

/usr/bin/osascript -e "display notification \"$\*\" with title \"Hey!\"" 

/usr/bin/say -v Samantha "Hey! $\*" 

# Setup: Add this to your /usr/local/bin in a file called hey. chmod +x it to make it an executable. 
# Usage: sleep 2 && hey wake up!
```

This is my local version, including a reference to Tara’s original Gist. Please _star_ Tara’s Gist if you use/like it.

Based on Tara’s script I decided to write a special script for **Docker** build, named: `docker-build` (Gist: [docker-build](https://gist.github.com/jonasbn/030008b965bebad2bb896aeb5518e07b)), sort of an equivalent of `docker-compose`.

> A disclaimer, these scripts are not implemented for distribution and need tweaking before being able to run on your machine and they are implemented on OSX. It should however be possible to dig up similar utilities on other operatings systems for emitting alerts, voice output and playing sound files, making the scripts work on other platforms.

```
#!/bin/bash

say -v Samantha "Docker build commencing...";

# Receives: messages and return value from Docker build
function emit() {

    if [ $2 -eq 0 ]
    then
        # green output
        echo -e "\033[92m$1";
    else
        # red output
        echo -e "\033[91m$1";
    fi

    # Resetting colouring
    echo -e "\033[0m";

    hey $1;
}

./docker-build.sh

if [ $? -eq 0 ]
then
    /usr/bin/afplay $HOME/Sounds/success.wav
    emit "Docker build completed" 0
else
    /usr/bin/afplay $HOME/Sounds/warning.wav
    emit "Docker build failed" 1
    exit 1
fi

exit 0
```

Do note that it uses both differentiated colorized output and sounds based on the success of the **Docker** build.  All my **Docker** builds have a `docker-build.sh` and `docker-run.sh` (and `docker-entrypoint.sh`) to avoid entering the same values over and over again for different projects and keeping the projects somewhat uniform – your shell history might not go as far back as your work log. [An example](https://github.com/jonasbn/terms_and_conditions_as_a_service_poc) using this approach can be found on GitHub.

On the forever fascinating Internet I fell over some [sound loops from Science Fiction movies](https://www.youtube.com/channel/UCF6R1ZDskjCeBMomUGCtxXw). Finding the “[Nostromo Ambient Engine Noise](https://youtu.be/_AmQbNItyko)” particularly stimulating I noticed it has some discrete beeps in the background, like something was indicating a pulse or something running and it reminded me of the cranes from the South Korean shipyard, where I have still not been able to dig up any snippets or examples.

Anyway I decided to see if I could incorporate the same sort of _pulse_ in my long running scripts. This sort of solves the issue of me not catching the termination signal, I can hear that the pulse is no longer emitted.

The prototype consists of two scripts (_please forgive my very basic Shell-scripting knowledge and style, it is not what I primarily code in, so suggestions for improvements are always welcome_).

`alive.sh` emits a sound every to seconds and runs _forever_.

```
#!/bin/bash 

while [1]; do 
    /usr/bin/afplay $HOME/Sounds/alive.wav; 
    sleep 2; 
done

exit 0
```

`fork.sh` forks of `alive-beep.sh` and does what ever is is supposed to do, when done it terminates (`kill`) `alive-beep.sh` and completes with emitting a sound indicating that it has finished, as for the docker-build script this could be changed into reflecting the outcome of the run, differentiating on sound and color.

```
#!/bin/bash
 
alive-beep.sh & 

sleep 6; 

kill $! 

/usr/bin/afplay $HOME/Sounds/success.wav 

exit 0
```

If we apply this to docker-build, it could look like the following:

```
#!/bin/bash

say -v Samantha "Docker build commencing...";

# Receives: messages and return value from Docker build
function emit() {

    if [ $2 -eq 0 ]
    then
        # green output
        echo -e "\033[92m$1";
    else
        # red output
        echo -e "\033[91m$1";
    fi

    # Resetting colouring
    echo -e "\033[0m";

    hey $1;
}

alive-beep.sh &

./docker-build.sh

kill $!

if [ $? -eq 0 ]
then
    /usr/bin/afplay $HOME/Sounds/success.wav
    emit "Docker build completed" 0
else
    /usr/bin/afplay $HOME/Sounds/warning.wav
    emit "Docker build failed" 1
    exit 1
fi

exit 0
```

(Gist: [docker-build](https://gist.githubusercontent.com/jonasbn/030008b965bebad2bb896aeb5518e07b/raw/1937fae99fdc44e667a67a6989514e6a95c459dc/docker-build))

I am far from done with experimenting with audible output, I need to try out other sounds, differentiated volume and general integration with more of my scripts.

If this article has inspired you and you come up with something cool, let me know. If you find issues with the scripts, please let me know.