Step 3: Setting up Software & Drivers on the Pi


#1

a. Setting up Spotify

To enable streaming music from Spotify, you need a premium account that has e-mail authentication. If you created your account with Facebook, there is an option to add an e-mail password authentication.

:triangular_flag_on_post: This account must use a username and password to authenticate, and not the Facebook authentication.

  • Create a Spotify application
  • Retrieve the client_id and the client_secret from the application
  • Keep this information at hand, and copy it in the “setup/config” file

b. Connecting the Hifiberry

To power the speaker and to improve the sound quality (the default sound quality on the raspberry Pi is … not the best) we are using a Hifiberry AMP+. There are many sound cards that you can use. Some are made specifically for the Raspberry Pi, although most sound cards ought to work. We decided to go with the HiFiBerry because it seemed like the easiest option to get started with at the time, and we’re happy with the result.

The HiFiBerry sits on top of the Raspberry Pi, as a shield. It requires a 12V power source to power itself and the Pi, and has a connector for hooking up speakers. In order to be recognized by the system, some minor modifications must be made to the ALSA config file, but the HiFiBerry tutorials make the process fairly straightforward.

From the /boot/config.txt file, remove the line:

dtparam=audio=on

And add the following line (this varies depending on the model of card you are using, here we are using a HiFiBerry AMP+)

dtoverlay=hifiberry-amp

And you’re set !


#2

Hi Snips Team,

I think i’ve mostly done the big part but for some reason I can’t play any music.
I skipped for the moment the arduino part waiting the neopixel ring to be delivered (far to complicate at least for me to use leds instead).
I don’t have any spotify account so I’ve connected a shared drive on the Raspberry and the music is available on mopidy.

When I’m triggering the hotword, it’s working (sound) but for some reason I can’t find any way to play the music I have.
Here is the result of the display_messages.py :

[23:23:38.141206] - hermes/hotword/detected
[23:23:38.201163] - hermes/hotword/wait
[23:23:38.251328] - hermes/asr/toggleOn
[23:23:38.252326] - hermes/audioServer/playFile: {“filePath”:"/usr/share/snips/dialogue/sound/start_of_input.wav"}
[23:23:41.449606] - hermes/asr/textCaptured: {“text”:“joue un peu de musique”,“likelihood”:0.86263454,“seconds”:2,“error”:null}
[23:23:41.513380] - hermes/asr/toggleOff
[23:23:41.515100] - hermes/audioServer/playFile: {“filePath”:"/usr/share/snips/dialogue/sound/end_of_input.wav"}
[23:23:41.516165] - hermes/nlu/query: {“text”:“joue un peu de musique”,“likelihood”:0.86263454,“seconds”:2,“error”:null}

(I used the assistant with the french parameter)
Here is the daemon.log :

Jul 30 23:39:32 spkr docker[394]: [21:39:32.110437] #033[32mINFO #033[0m:#033[1msnips_hotword #033[0m: Hotword detected
Jul 30 23:39:32 spkr docker[394]: [21:39:32.141880] #033[32mINFO #033[0m:#033[1msnips_dialogue::dialogue#033[0m: State: Idle, incoming Message: Hotword(Detected)
Jul 30 23:39:32 spkr docker[394]: [21:39:32.142020] #033[32mINFO #033[0m:#033[1msnips_dialogue::services#033[0m: publish Hotword(Wait)
Jul 30 23:39:32 spkr docker[394]: [21:39:32.142094] #033[32mINFO #033[0m:#033[1msnips_dialogue::services#033[0m: publish ASR(ToggleOn)
Jul 30 23:39:32 spkr docker[394]: [21:39:32.142158] #033[32mINFO #033[0m:#033[1msnips_dialogue::services#033[0m: publish AudioServer(PlayFile)
Jul 30 23:39:32 spkr docker[394]: [21:39:32.142223] #033[32mINFO #033[0m:#033[1msnips_dialogue::dialogue#033[0m: Current State: WaitingQuery
Jul 30 23:39:32 spkr docker[394]: [21:39:32.203251] #033[32mINFO #033[0m:#033[1msnips_audio_server #033[0m: using output “default” for “/usr/share/snips/dialogue/sound/start_of_input.wav”, WavSpec { channels: 2, sample_rate: 22050, bits_per_sample: 16, sample_format: Int }
Jul 30 23:39:32 spkr docker[394]: 2017/07/30 21:39:32 Opening STT stream
Jul 30 23:39:32 spkr docker[394]: 2017/07/30 21:39:32 Start listening
Jul 30 23:39:33 spkr docker[394]: 2017/07/30 21:39:33 getResult: START_OF_SPEECH
Jul 30 23:39:35 spkr docker[394]: 2017/07/30 21:39:35 getResult: END_OF_SPEECH
Jul 30 23:39:35 spkr docker[394]: 2017/07/30 21:39:35 getResult: ENDPOINTER_EVENT_UNSPECIFIED
Jul 30 23:39:35 spkr docker[394]: 2017/07/30 21:39:35 getResult: alternatives:<transcript:“joue un peu de musique” confidence:0.97903806 > is_final:true
Jul 30 23:39:35 spkr docker[394]: 2017/07/30 21:39:35 Message published -> {“text”:“joue un peu de musique”,“likelihood”:0.97903806,“seconds”:3,“error”:null}
Jul 30 23:39:35 spkr docker[394]: [21:39:35.623571] #033[32mINFO #033[0m:#033[1msnips_dialogue::dialogue#033[0m: State: WaitingQuery, incoming Message: ASR(TextCaptured)
Jul 30 23:39:35 spkr docker[394]: [21:39:35.623713] #033[32mINFO #033[0m:#033[1msnips_dialogue::services#033[0m: publish ASR(ToggleOff)
Jul 30 23:39:35 spkr docker[394]: [21:39:35.623797] #033[32mINFO #033[0m:#033[1msnips_dialogue::services#033[0m: publish AudioServer(PlayFile)
Jul 30 23:39:35 spkr docker[394]: [21:39:35.628273] #033[32mINFO #033[0m:#033[1msnips_dialogue::services#033[0m: publish NLU(Query)
Jul 30 23:39:35 spkr docker[394]: [21:39:35.628502] #033[32mINFO #033[0m:#033[1msnips_dialogue::dialogue#033[0m: Current State: WaitingIntent
Jul 30 23:39:35 spkr docker[394]: 2017/07/30 21:39:35 Stopped listening
Jul 30 23:39:35 spkr docker[394]: [21:39:35.685689] #033[32mINFO #033[0m:#033[1msnips_audio_server #033[0m: using output “default” for “/usr/share/snips/dialogue/sound/end_of_input.wav”, WavSpec { channels: 2, sample_rate: 22050, bits_per_sample: 16, sample_format: Int }

I’m suspecting some issue with the spotify account not enabled but how to be sure and how to use a local/network library instead ?

Regards


#3

Hi @Wismer !
Thanks a lot for your interest in spkr and in Snips !

By reading at the logs you provided, it seems that you successfully installed the Snips NLU engine.

Let’s make sure you can play songs locally.

First, check that you enable the mopidy-local extension, that allows to read local files. To do so, edit the /etc/mopidy/mopidy.conf file.
Look for the local section in the file.
Edit it to make it look like this :

[local]
enabled = true
library = json
media_dir = /home/pi/music
scan_timeout = 1000
scan_flush_threshold = 100
scan_follow_symlinks = false
excluded_file_extensions =
  .directory
  .html
  .jpeg
  .jpg
  .log
  .nfo
  .png
  .txt

Don’t forget to replace media_dir with the folder your music is in.
We now need to scan your music so that Mopidy can build an index :

sudo mopidyctl local scan

You now need to restart mopidy :

sudo systemctl restart mopidy.service 

Now open up a browser on your computer, and head over to http://spkr.local:6680/iris/#/library/local .
You should see your local music !

Make sure you can play the music from Iris.

Now, we just need to add support for local playback. Open up the file home-python/home/music.py. Edit the search_spotify method the Music class, so that it looks like this (add ‘local’ to the URIs)

   def search_spotify(self, parameters):
        spotify = parameters.copy()
        spotify['uris'] = ['spotify:','local:']
        return self.search(spotify)

Restart the spkr.python.service service :

sudo systemctl restart spkr.python.service

You should be all setup !


#4

Hi Anthony,

Thanks for the fast reply, the Snips project is my first one on Rasp and Arduino and it’s a nice and challenging project to start with !

I’ve checked the mopidy conf and it was already alright and my music (2 tracks for the moment) is playable on Iris.

But this part was definitly missing :

So I’ve applied this and restarted the spkr service.

Unfortunatly it’s still not playing my music.

Checking the daemon.log again, I see some errors.
There are some ALSA Lib errors but as the music is playing on Iris or aplay, I think it should not be a major issue.

But there are also some error on spkr

Jul 31 20:44:49 spkr docker[397]: 2017-07-31 18:44:49,044 INFO spawned: ‘snips-queries’ with pid 135
Jul 31 20:44:49 spkr docker[397]: [18:44:49.164482] #033[31mERROR#033[0m:#033[1msnips_queries#033[0m: missing field name at line 86 column 1
Jul 31 20:44:49 spkr docker[397]: 2017-07-31 18:44:49,183 INFO exited: snips-queries (exit status 1; not expected)

And another one

Jul 31 20:55:23 spkr docker[397]: INFO: 2017/07/31 18:55:23 transport: http2Client.notifyError got notified that the client transport was broken EOF.

I hope this can lead somewhere.
Regards


#5

Hi @Anthony or @quentin

i have 2 questions regarding the tutorial

  1. i´m using jabra speak 510 and justboom amp hat and i wanna hear the speaker output via justboom. But every time i got the output via jabra.
    I already changed the config.txt and added

    #dtparam=audio=on
    dtparam=audio=off
    dtoverlay=i2s-mmap
    dtoverlay=justboom-dac

and rebootet. But it does not work.
I also added .asoundrc

pcm.!default {
type asym
capture.pcm "mic"
playback.pcm “speaker”
}
pcm.mic {
type plug
slave {
pcm “hw:,”
}
}
pcm.speaker {
type plug
slave {
pcm “hw:,”
}
}

but nothing changed. How can i set the justboom amp hat as primary speaker?

  1. I did not understand where and how i can put my credentials from spotify to the setup/config.The config file is empty…

Thx in advance Philipp