ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
My motive is to measure time taken for delayed audio playback through shell script..
The steps which I thought are as below:
1)
a) The user will press Enter to start the playback.
b) A Timer should be started at this point to measure the delayed audio playback.
c) The actual playback will be done through the "aplay" tool through the script. "aplay" is blocking call, I mean until the audio is completely played, the contol will remain on it.
2) Whenever the user will hear the actual sound, he will press "Enter" to stop the timer.
Now the problem is how can I do these multi tasks (playback and user interaction for time measurement) at the same time.
Thanks,
I thought of it but there seems to be some issues due to which I cant proceed with it.
If I run aplay in the background (suppose for a audio file of length 5 mins.), then in the foreground (the user interaction) the work will get over sooner and the control will come out from my function. But the audio is still getting played in the background..
I want the user interaction to happen in parallel, but the function should not bail out until all of my work (including playing of the full audio) are finished.
First, obtain process ID (pid) of aplay using $! variable, then use kill command to send any signal to the process (SIGTERM for example) to terminate it:
Code:
file=./Noise.wav
aplay $file &
pid=$!
read ok
kill $pid
I assume here that you want to stop playback prematurely. Previously suggested command, wait $pid, will wait for aplay to complete (so you will hear whole song to the end).
Last edited by firstfire; 09-18-2012 at 06:50 AM.
Reason: Typos.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.