<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="http://dev1galaxy.org/extern.php?action=feed&amp;tid=4380&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[Dev1 Galaxy Forum / [SOLVED] how to randomly start audio file, via script,]]></title>
		<link>http://dev1galaxy.org/viewtopic.php?id=4380</link>
		<description><![CDATA[The most recent posts in [SOLVED] how to randomly start audio file, via script,.]]></description>
		<lastBuildDate>Mon, 21 Jun 2021 17:05:15 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[Re: [SOLVED] how to randomly start audio file, via script,]]></title>
			<link>http://dev1galaxy.org/viewtopic.php?pid=30360#p30360</link>
			<description><![CDATA[<div class="quotebox"><cite>ralph.ronnquist wrote:</cite><blockquote><div><div class="quotebox"><cite>zapper wrote:</cite><blockquote><div><p>&#160; $HOME/Zeal/Music*/*.{opus}</p></div></blockquote></div><p> I think bash doesn&#039;t handle braces around singleton option well; it only works well when there are options. And it also has to find some * match for every option otherwise it results in the glob string itself. Though, perhaps inserting a prior </p><div class="codebox"><pre><code>shopt -s nullglob</code></pre></div><p> changes that.</p><p>Thus, in effect, all those selections ending <span class="bbc">{opus}</span> end up as &quot;bad pathnames&quot; when picked for the later play command.</p><p>In other words, remove the braces for all <span class="bbc">{opus}</span> and insert that <span class="bbc">shopt</span> command, and then it hopefully will work consistently.</p></div></blockquote></div><p>Hmm.... I didn&#039;t really understand how to do that... that being said, Dice&#039;s command context was smaller and actually more usable.</p><p>But it does have the same issue oddly enough.</p><p>I assume its the same problem in the sense of how often it fails. I will test more though and say otherwise if works more.</p><p>EDIT: Not even close, Dice&#039;s script seems to work more than 90% of the time.</p><p>Thank you Dice, you seem to know your software well.</p><p>Also here is what I did:</p><p>#!/bin/bash<br />find ~/Folder/ -type f -name &#039;*.opus&#039; | shuf -n 1 | xargs -d &quot;\n&quot; play</p>]]></description>
			<author><![CDATA[dummy@example.com (zapper)]]></author>
			<pubDate>Mon, 21 Jun 2021 17:05:15 +0000</pubDate>
			<guid>http://dev1galaxy.org/viewtopic.php?pid=30360#p30360</guid>
		</item>
		<item>
			<title><![CDATA[Re: [SOLVED] how to randomly start audio file, via script,]]></title>
			<link>http://dev1galaxy.org/viewtopic.php?pid=30349#p30349</link>
			<description><![CDATA[<div class="quotebox"><cite>zapper wrote:</cite><blockquote><div><p>&#160; $HOME/Zeal/Music*/*.{opus}</p></div></blockquote></div><p> I think bash doesn&#039;t handle braces around singleton option well; it only works well when there are options. And it also has to find some * match for every option otherwise it results in the glob string itself. Though, perhaps inserting a prior </p><div class="codebox"><pre><code>shopt -s nullglob</code></pre></div><p> changes that.</p><p>Thus, in effect, all those selections ending <span class="bbc">{opus}</span> end up as &quot;bad pathnames&quot; when picked for the later play command.</p><p>In other words, remove the braces for all <span class="bbc">{opus}</span> and insert that <span class="bbc">shopt</span> command, and then it hopefully will work consistently.</p>]]></description>
			<author><![CDATA[dummy@example.com (ralph.ronnquist)]]></author>
			<pubDate>Mon, 21 Jun 2021 12:55:42 +0000</pubDate>
			<guid>http://dev1galaxy.org/viewtopic.php?pid=30349#p30349</guid>
		</item>
		<item>
			<title><![CDATA[Re: [SOLVED] how to randomly start audio file, via script,]]></title>
			<link>http://dev1galaxy.org/viewtopic.php?pid=30346#p30346</link>
			<description><![CDATA[<p>found this one liner that works ok with mpg123, picks&#160; a random mp3 from Music dir.</p><div class="codebox"><pre><code>find ~/Music -type f -name &#039;*.mp3&#039; | shuf -n 1 | xargs -d &quot;\n&quot; mpg123</code></pre></div><p>you could use any music player,&#160; not sure how to add other/more file formats though.</p><p>Cant figure out how to get this to open in own terminal to see the output.</p>]]></description>
			<author><![CDATA[dummy@example.com (dice)]]></author>
			<pubDate>Mon, 21 Jun 2021 12:26:26 +0000</pubDate>
			<guid>http://dev1galaxy.org/viewtopic.php?pid=30346#p30346</guid>
		</item>
		<item>
			<title><![CDATA[Re: [SOLVED] how to randomly start audio file, via script,]]></title>
			<link>http://dev1galaxy.org/viewtopic.php?pid=30342#p30342</link>
			<description><![CDATA[<p>Fascinating it is, your script does work with the modifications now, but... theres one small, catch...</p><p>This is what it looks like now:</p><p>#!/bin/bash<br />AUDIO=( <br />&#160; $HOME/Zeal/Music*/*.{opus}<br />&#160; $HOME/Zeal/Music*.opus<br />&#160; $HOME/Zanra/Music*/*.{opus}<br />&#160; $HOME/Zanra/Music*.opus<br />&#160; $HOME/Kai/Music*/*.{opus}<br />&#160; $HOME/Kai/Music*.opus<br />&#160; $HOME/Drasu/Music*/*.{opus}<br />&#160; $HOME/Drasu/Music*.opus<br />&#160; &#160;/usr/share/sounds/alsa*.wav<br />)<br />LENGTH=${#AUDIO[@]}<br />PICK=$(( RANDOM % $LENGTH ))<br />play ${AUDIO[$PICK]}<br />echo ${AUDIO[@]}</p><p>And for some reason, it fails sometimes... to trigger, like 1/3 of the time it works for me. I wonder what I am doing wrong...</p><p>Gives me errors, despite my folders being there and such...</p><p>play WARN alsa: can&#039;t encode 0-bit Unknown or not applicable<br />play FAIL formats: can&#039;t open input file</p><p>This happens like 1/3 of the time. weird it is.</p>]]></description>
			<author><![CDATA[dummy@example.com (zapper)]]></author>
			<pubDate>Mon, 21 Jun 2021 11:47:34 +0000</pubDate>
			<guid>http://dev1galaxy.org/viewtopic.php?pid=30342#p30342</guid>
		</item>
		<item>
			<title><![CDATA[Re: [SOLVED] how to randomly start audio file, via script,]]></title>
			<link>http://dev1galaxy.org/viewtopic.php?pid=30340#p30340</link>
			<description><![CDATA[<p>Expanded example with some more audio paths, and also that I added &quot;$&quot; for &quot;$RANDOM&quot; just for symmetry (although it shouldn&#039;t be needed) and removed the braces for $PICK (also not needed).</p><div class="codebox"><pre><code>#!/bin/bash
AUDIO=( 
    $HOME/folder*/*.{wav,mp3,ogg}
    $HOME/with/some/path/*.mp3
    /usr/share/sounds/alsa/*.wav
)
LENGTH=${#AUDIO[@]}
PICK=$(( $RANDOM % $LENGTH ))
play ${AUDIO[$PICK]}</code></pre></div><p>In detail, </p><ul><li><p>the AUDIO assignment is the collection of possible audio files, which in this example includes any files with extensions wav, mp3 or ogg in any home folder whose name starts with &quot;folder&quot;, plus any mp3 file in the folder path &quot;with/some/path&quot; from the home folder, plus any wav file in (system) folder &quot;/usr/share/sounds/alsa/&quot;; </p></li><li><p>the LENGTH assignment is the number of pathnames in the AUDIO list;</p></li><li><p>the PICK assignment is an integer between 0 and LENGTH-1 picked from a uniform distribution between 0 and 32767, modulo the length (which makes it favour lower numbers); and</p></li><li><p>the play command is of the PICK:th pathname of AUDIO list</p></li></ul><p>I&#039;m sure you can edit the audio paths to suit your needs.</p><p>But, there&#039;s something funny going on if it doesn&#039;t pick at random; perhaps a misspelling? But if you used Copy-and-Paste then that wouldn&#039;t be the case. The other option is that the audio selection doesn&#039;t find more than one file.. You might check that by inserting</p><div class="codebox"><pre><code>echo ${AUDIO[@]}</code></pre></div><p>immediately after the assignment, and review that output....</p>]]></description>
			<author><![CDATA[dummy@example.com (ralph.ronnquist)]]></author>
			<pubDate>Mon, 21 Jun 2021 04:17:36 +0000</pubDate>
			<guid>http://dev1galaxy.org/viewtopic.php?pid=30340#p30340</guid>
		</item>
		<item>
			<title><![CDATA[Re: [SOLVED] how to randomly start audio file, via script,]]></title>
			<link>http://dev1galaxy.org/viewtopic.php?pid=30337#p30337</link>
			<description><![CDATA[<div class="quotebox"><cite>ralph.ronnquist wrote:</cite><blockquote><div><p>The script could be something simple, like</p><div class="codebox"><pre><code>#!/bin/bash
AUDIO=( $HOME/folder*/*.{wav,mp3,ogg} )
LENGTH=${#AUDIO[@]}
PICK=$(( RANDOM % $LENGTH ))
play ${AUDIO[${PICK}]}</code></pre></div><p>Then it depends on which display management you are using; with xfce4 you would go to &quot;Settings&quot;:&quot;Session and Startup&quot; and add a new entry for &quot;Application Autorstart&quot; and there point at your executable script. That would set it up so that that script gets executed upon login.</p><p>If you want it tied to console login you might add it to your &quot;.bashlogin&quot;, or similar depending on which shell you are using.</p></div></blockquote></div><p>Hmm, it doesn&#039;t seem to pick a random audio to play, always plays the same one when I tried it.</p><p>I was going to use jwm&#039;s method to autostart it to be honest.</p><p>I am curious, though beyond that, how would I make it only pick one of those audios to play before script stopping.</p><p>And also, if there is a way to add code behind before the audio part,&#160; say there is one master folder and it has 5 different folders to choose from... I think you know where I am going with this right? </p><p>That and figuring out why it doesn&#039;t randomly select a different one each time I trigger it, is what I need to figure out.</p>]]></description>
			<author><![CDATA[dummy@example.com (zapper)]]></author>
			<pubDate>Mon, 21 Jun 2021 00:36:50 +0000</pubDate>
			<guid>http://dev1galaxy.org/viewtopic.php?pid=30337#p30337</guid>
		</item>
		<item>
			<title><![CDATA[Re: [SOLVED] how to randomly start audio file, via script,]]></title>
			<link>http://dev1galaxy.org/viewtopic.php?pid=30336#p30336</link>
			<description><![CDATA[<p>The script could be something simple, like</p><div class="codebox"><pre><code>#!/bin/bash
AUDIO=( $HOME/folder*/*.{wav,mp3,ogg} )
LENGTH=${#AUDIO[@]}
PICK=$(( RANDOM % $LENGTH ))
play ${AUDIO[${PICK}]}</code></pre></div><p>Then it depends on which display management you are using; with xfce4 you would go to &quot;Settings&quot;:&quot;Session and Startup&quot; and add a new entry for &quot;Application Autorstart&quot; and there point at your executable script. That would set it up so that that script gets executed upon login.</p><p>If you want it tied to console login you might add it to your &quot;.bashlogin&quot;, or similar depending on which shell you are using.</p>]]></description>
			<author><![CDATA[dummy@example.com (ralph.ronnquist)]]></author>
			<pubDate>Sun, 20 Jun 2021 23:11:48 +0000</pubDate>
			<guid>http://dev1galaxy.org/viewtopic.php?pid=30336#p30336</guid>
		</item>
		<item>
			<title><![CDATA[[SOLVED] how to randomly start audio file, via script,]]></title>
			<link>http://dev1galaxy.org/viewtopic.php?pid=30332#p30332</link>
			<description><![CDATA[<p>With sox, </p><p>This is gonna sound weird, insane and odd,</p><p>But I wanted when I login, for a script to start that would randomly choose from one folder,</p><p>Say its folder 1, and say it has 4 folders, randomly choose one of those folders, and play an audio from one of those.</p><p>And also, if it has folders within the four folders, it will randomly choose one of them.</p><p>This sounds crazy, and why would I want it right? </p><p>I have an idea how to do a tiny bit of it, but not much.</p><p>I have found scripts ike this for thinkpads aka:</p><p>#!/bin/bash</p><p>declare -i ID<br />ID=`xinput list | grep -Eo &#039;TouchPad\s*id\=[0-9]{1,2}&#039; | grep -Eo &#039;[0-9]{1,2}&#039;`<br />declare -i STATE<br />STATE=`xinput list-props $ID|grep &#039;Device Enabled&#039;|awk &#039;{print $4}&#039;`<br />if [ $STATE -eq 1 ]<br />then<br />&#160; &#160; xinput disable $ID<br />&#160; &#160; echo &quot;Touchpad disabled.&quot;<br />else<br />&#160; &#160; xinput enable $ID<br />&#160; &#160; echo &quot;Touchpad enabled.&quot;<br />fi</p><p>the above script is for disabling the touchpad... <img src="http://dev1galaxy.org/img/smilies/smile.png" width="15" height="15" alt="smile" /></p><p>Without system dumb.</p><p>Anyways give me a holler if you know how to do the audio random playing thing. Aka, the random audio play script I want.</p><p>I am not a programmer, so I cannot even figure out how this can be done... ;P</p>]]></description>
			<author><![CDATA[dummy@example.com (zapper)]]></author>
			<pubDate>Sun, 20 Jun 2021 16:22:31 +0000</pubDate>
			<guid>http://dev1galaxy.org/viewtopic.php?pid=30332#p30332</guid>
		</item>
	</channel>
</rss>
