Results 1 to 3 of 3

Thread: Play a sound when a condition is met?

  1. #1
    Join Date
    Dec 2007
    Location
    Bombay
    Beans
    5,742
    Distro
    Lubuntu 14.04 Trusty Tahr

    Play a sound when a condition is met?

    I have this script to prevent screen blanking when the CPU usage is > 8% :
    Code:
    #!/usr/bin/env bash
    
    sleep_period=8m 
    
    while true; do
      if ps -eo %C --sort -%cpu | head -2 | awk 'NR==2 { exit !($1>8); }'; then
          xdotool key Shift
      fi
      sleep ${sleep_period}
    done
    Can I have a sound play whenever xdotool key Shift is executed? I'm thinking of something like
    Code:
    mplayer --really-quiet /usr/share/sounds/freedesktop/stereo/bell.oga
    My system is Lubuntu 13.04. It doesn't have Pulseaudio as far as I can tell and so paplay is not an option. I have alsa-utils but aplay gives a horrible sound, like white noise.

    Edit: I'm reading a bit about Pulseaudio v/s alsa and some people feel that alsa can't handle two programs playing sound at the same time. So, I'm wondering whether my question is valid and if it is, whether alsa can do what I want when I watching a video, the most typical situation when I don't want to screen to blank.
    Last edited by vasa1; October 9th, 2013 at 07:23 AM.
    de gustibus et coloribus non est disputandum -- Wiktionary

  2. #2
    Join Date
    Aug 2011
    Location
    47°9′S 126°43W
    Beans
    1,853
    Distro
    Kubuntu 12.10 Quantal Quetzal

    Re: Play a sound when a condition is met?

    http://linux.die.net/man/1/beep

    (beep is your friendly distro repository)
    Warning: unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.

  3. #3
    Join Date
    Apr 2011
    Location
    Maryland
    Beans
    1,461
    Distro
    Kubuntu 12.04 Precise Pangolin

    Re: Play a sound when a condition is met?

    See also this thread where the program 'espeak' was mentioned. That might also be helpful (or at least entertaining!):

    http://ubuntuforums.org/showthread.php?t=2096908

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •