How do I play a sound in Octave?
On one of my Linux machines, I created the following ofsndplay script to work around the hard-wired dependency:
$ cat /usr/bin/ofsndplay
#!/bin/sh
## Coping with stupid dependency on ofsndplay in octave
play -t au -
This particular script uses the SoX play
utility.
Admittedly, the comment is unnecessary for the functionality but it certainly made me feel better....
Using soundsc in Octave, on Windows 7
The file you linked to includes documentation at the top, which includes the following:
## This function writes the audio data through a pipe to the program
## "play" from the sox distribution.
So you need to install sox, for starters. This will include play.exe
. Then you have to either set the value of the global variable sound_play_utility
in Octave to reflect where you installed sox
, or make sure the file_in_path(EXEC_PATH)
stuff can find play.exe
. Looking a few lines down from the snippet you posted, it looks like the file passes that variable to popen
, which is supposed to launch a new process. I've never done anything like that on Octave on a Windows machine, so I can't help you on the exact details.
How can I wait for an (audio play) command to finish before executing the next one, in Octave?
You could do a busy loop on the play status:
while strcmpi(player.Running, 'on')
pause(.1);
endwhile
The pause isn't required, or could be doing something else instead - I just use in the example to limit the CPU usage.
Or
while isplaying(player)
pause(.1);
endwhile
You could also use playblocking(player) instead
From here:
33.3.1 Playback
The following methods are used to control player playback.
...
playblocking (player)
playblocking (player, start)
playblocking (player, limits)
Play audio stored in the audioplayer object player with blocking.
Given optional argument start, begin playing at start samples in
the recording. Given a two-element vector limits, begin and end
playing at the number of samples specified by the elements of the
vector.
isplaying (player)
Return true if the audioplayer object player is currently playing
back audio and false otherwise.
Related Topics
How to Send Data to Local Clipboard from a Remote Ssh Session
How to Perform Grep Operation on All Files in a Directory
How to Show Line Number When Executing Bash Script
How to Find Out Mount/Partition a Directory or File Is On? (Linux Server)
How to Get the Contents of a Webpage in a Shell Variable
How to List (Ls) the 5 Last Modified Files in a Directory
Get Final Url After Curl Is Redirected
Find All Storage Devices Attached to a Linux MAChine
Recursive Copy of a Specific File Type Maintaining the File Structure in Unix/Linux
Combine a Shell Script and a Zip File into a Single Executable for Deployment
Getting Disconnection Notification Using Tcp Keep-Alive on Write Blocked Socket
Why Does %Rbp Point to Nothing
Centos Error - Sudo: Effective Uid Is Not 0, Is Sudo Installed Setuid Root
How Does a Linux Socket Buffer Overflow
How to Fix Permission Denied for .Git/ Directory When Performing Git Push