{"id":752,"date":"2016-03-06T17:01:45","date_gmt":"2016-03-06T16:01:45","guid":{"rendered":"http:\/\/heppg.de\/ikg\/wordpress\/?p=752"},"modified":"2016-03-07T21:22:46","modified_gmt":"2016-03-07T20:22:46","slug":"raspberry-pi-scratch-1-4-sound-recording","status":"publish","type":"post","link":"https:\/\/heppg.de\/ikg\/wordpress\/?p=752","title":{"rendered":"raspberry pi scratch 1.4 sound recording"},"content":{"rendered":"<p>Scratch 1.4 can record sound. But unfortunately the setup is not simple.<\/p>\n<p>The comments here are based on raspbian <strong>2016-02-26<\/strong> and scratch <strong>2016-01-15<\/strong>.<\/p>\n<h3>Recording sound in scratch 1.4<\/h3>\n<p>I connected a simple USB sound card. This card is connected to a microphone and a pair of speakers. The reason to use a card like this is especially the mic-input. Raspberry pi does not have an input on board.<\/p>\n<p><a href=\"http:\/\/heppg.de\/ikg\/wordpress\/wp-content\/uploads\/2016\/03\/sound_device.png\" rel=\"attachment wp-att-758\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-758\" src=\"http:\/\/heppg.de\/ikg\/wordpress\/wp-content\/uploads\/2016\/03\/sound_device.png\" alt=\"sound_device\" width=\"187\" height=\"196\" \/><\/a><\/p>\n<p>Doublecheck that your adapter is recognized from operating system. Open a terminal window ad enter &#8216;lsusb&#8217;. The output should show your sound device, here the output from my system:<\/p>\n<pre>pi@raspberrypi:~ $ lsusb\r\nBus 001 Device 009: ID 0d8c:013c C-Media Electronics, Inc. CM108 Audio Controller<\/pre>\n<p>On desktop, the proper audio device needs to be selected.<\/p>\n<p><a href=\"http:\/\/heppg.de\/ikg\/wordpress\/wp-content\/uploads\/2016\/03\/device_selection.png\" rel=\"attachment wp-att-753\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-753 \" src=\"http:\/\/heppg.de\/ikg\/wordpress\/wp-content\/uploads\/2016\/03\/device_selection.png\" alt=\"device_selection\" width=\"228\" height=\"127\" \/><\/a><\/p>\n<p>I had to reboot the computer to get the changes working. The &#8216;unable to connect&#8230;&#8217;-popup clearly indicates that there are errors.<\/p>\n<p><a href=\"http:\/\/heppg.de\/ikg\/wordpress\/wp-content\/uploads\/2016\/03\/device_not_found.png\" rel=\"attachment wp-att-756\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-756\" src=\"http:\/\/heppg.de\/ikg\/wordpress\/wp-content\/uploads\/2016\/03\/device_not_found.png\" alt=\"device_not_found\" width=\"318\" height=\"85\" \/><\/a><\/p>\n<p>In scratch, check the audio output first. Let the cat &#8216;meow&#8217; a few times.<\/p>\n<p><a href=\"http:\/\/heppg.de\/ikg\/wordpress\/wp-content\/uploads\/2016\/03\/record_start.png\" rel=\"attachment wp-att-754\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-754\" src=\"http:\/\/heppg.de\/ikg\/wordpress\/wp-content\/uploads\/2016\/03\/record_start.png\" alt=\"record_start\" width=\"319\" height=\"227\" \/><\/a><\/p>\n<p>Start recording with &#8216;New sound, record&#8217;. The sound recorder popup should be displayed. The red button starts recording.<\/p>\n<p><a href=\"http:\/\/heppg.de\/ikg\/wordpress\/wp-content\/uploads\/2016\/03\/sound_volume.png\" rel=\"attachment wp-att-755\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-755\" src=\"http:\/\/heppg.de\/ikg\/wordpress\/wp-content\/uploads\/2016\/03\/sound_volume.png\" alt=\"sound_volume\" width=\"265\" height=\"91\" \/><\/a><\/p>\n<p>There is a nice volume indication shown in the bar.<\/p>\n<p>Press stop \u25a0 and ok. The recording is available now.<\/p>\n<p>Unfortunately, the sound was played double the speed, faster and higher than recorded. Seems to be a bug in scratch. Exporting the audio file to file system and importing this back results in normal playback.<\/p>\n<p>There is no possibility to control recording by program code.<\/p>\n<h3>Advanced commands for command line<\/h3>\n<p>On my system, it was possible to record sound from mic by<\/p>\n<pre>arecord -D plughw:1,0 test.wav<\/pre>\n<p>With aplay it is possible to reply these data<\/p>\n<pre>\u00a0aplay -D plughw:1,0 test.wav<\/pre>\n<h3>Recording sound and playback sound with scratchClient<\/h3>\n<p>Recording sound is possible with scratchClient controlled by scratch runtime.<br \/>\nThis functionality is implemented by calling linux commands &#8216;arecord&#8217; and &#8216;aplay&#8217;.<\/p>\n<p>The adapter needed is &#8216;adapter.linux.Linux_ARECORD_Adapter&#8217;. It stores the files in a predefined directory. It uses the linux arecord command. You need to be familiar with alsa devices; this device needs to be specified.<\/p>\n<p>Sample script is<\/p>\n<p><a href=\"http:\/\/heppg.de\/ikg\/wordpress\/wp-content\/uploads\/2016\/03\/linux_arecord.gif\" rel=\"attachment wp-att-766\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-766\" src=\"http:\/\/heppg.de\/ikg\/wordpress\/wp-content\/uploads\/2016\/03\/linux_arecord.gif\" alt=\"linux_arecord\" width=\"149\" height=\"219\" \/><\/a><\/p>\n<p>Set the file name, then start recording and stop as needed. There is a timeout specified in the adapter config.<\/p>\n<p>Sample config file is config\/config_linux_arecord.xml<\/p>\n<p>Playback can be done by adapter adapter.linux.Linux_APLAY_Adapter. Sample script is<\/p>\n<p><a href=\"http:\/\/heppg.de\/ikg\/wordpress\/wp-content\/uploads\/2016\/03\/linux_aplay.gif\" rel=\"attachment wp-att-767\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-767\" src=\"http:\/\/heppg.de\/ikg\/wordpress\/wp-content\/uploads\/2016\/03\/linux_aplay.gif\" alt=\"linux_aplay\" width=\"166\" height=\"93\" \/><\/a><\/p>\n<p>Replay one file in a loop needs to set the file name &#8216;wave&#8217; to blank in between, as only changing names are transmitted to scratchClient.<\/p>\n<p>Sample config file is config\/config_linux_aplay.xml<\/p>\n<p>The files recorded or available for playback are NOT included in the scratch code. So when you move your scratch application to another computer, you need to move your files too.<\/p>\n<p>Use same directory for record and playback, when a scratch program needs play earlier recorded sound.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Scratch 1.4 can record sound. But unfortunately the setup is not simple. The comments here are based on raspbian 2016-02-26 and scratch 2016-01-15. Recording sound in scratch 1.4 I connected a simple USB sound card. This card is connected to a microphone and a pair of speakers. The reason to use a card like this [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[29],"class_list":["post-752","post","type-post","status-publish","format-standard","hentry","category-scratch","tag-sound"],"_links":{"self":[{"href":"https:\/\/heppg.de\/ikg\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/752","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/heppg.de\/ikg\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/heppg.de\/ikg\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/heppg.de\/ikg\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/heppg.de\/ikg\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=752"}],"version-history":[{"count":8,"href":"https:\/\/heppg.de\/ikg\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/752\/revisions"}],"predecessor-version":[{"id":768,"href":"https:\/\/heppg.de\/ikg\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/752\/revisions\/768"}],"wp:attachment":[{"href":"https:\/\/heppg.de\/ikg\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=752"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/heppg.de\/ikg\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=752"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/heppg.de\/ikg\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=752"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}