class Object

Public Instance Methods

beep(a, b) click to toggle source

Windows-specific methods

# File lib/rubysounds.rb, line 187
def beep(a, b)
        if $winlib
                if $operative_system == "win"
                        Sound.beep(a, b)
                else
                        dub("the beep method is only avaible on Windows operative system")
                end
        else
                dub("Beep is not avaible. You need to gem install win32-sounds")
        end
end
dub(text) click to toggle source
# File lib/rubysounds.rb, line 175
def dub(text)
        puts(text)
        speak(text)
end
killallsounds() click to toggle source
# File lib/rubysounds.rb, line 98
def killallsounds
        puts "Exiting"
        # Kill all children sounds
        for child_sound in $children_sounds    
                #puts child_sound.pid
                # Kill child process...
                #Process.kill("QUIT", child_sound.pid)
                if $operative_system == "win"
                        system("Taskkill /PID " + child_sound.pid.to_s + " /F")
                else
                        system("kill " + child_sound.pid.to_s)
                end
                #$children_sounds.delete(child_sound)
                # This prevents the process from becoming defunct
                #child_sound.close
        end    
        # Kill main process
        exit 130
end
ms_win_play(path) click to toggle source
# File lib/rubysounds.rb, line 200
def ms_win_play(path)
        if $winlib
                Sound.play(path)
        else
                dub("Beep is not avaible. You need to gem install win32-sounds")
        end
end
play(target, wait: true, bg: true, dummy: true, volume: 100, loop: false) click to toggle source
# File lib/rubysounds.rb, line 128
def play(target, wait: true, bg: true, dummy: true, volume: 100, loop: false)

        # VLC command options
        if $operative_system == "win"
                vlccmd = "vlc "
                if bg 
                        vlccmd += "-I null "
                end
                
                vlccmd += "--play-and-exit "
                
                if (bg == false) && (dummy == true)
                        vlccmd += "--intf dummy "
                end
        else
                vlccmd = "cvlc --play-and-exit "      
        end
        
        vlccmd += "--directx-volume " + (volume.to_f/100).to_s + " "
        
        if loop
                vlccmd += "--loop "
        end
        
        # DEBUG ONLY
        #puts(vlccmd)
        
        io = IO.popen(vlccmd + target)
        $children_sounds.push(io)
        # Wait for the sound to end option
        if wait
                Process.wait(io.pid)
        end
        
        #system(vlccmd + target)
        #Thread.new { system(vlccmd + target) }
        
end
speak(text, language: "en", wait: true, bg: true, volume: 100, loop: false) click to toggle source
# File lib/rubysounds.rb, line 168
def speak(text, language: "en", wait: true, bg: true, volume: 100, loop: false)
        Speech.new(text, language).save("temp.wav")
        play("temp.wav", wait: wait, bg: bg, volume: volume, loop: loop)
        File.delete("temp.wav")
end