Class: OpenHAB::Core::Actions::Audio

Inherits:
Object
  • Object
show all
Defined in:
lib/openhab/core/actions/audio.rb,
lib/openhab/rspec/openhab/core/actions.rb

Overview

See Also:

Class Method Summary collapse

Class Method Details

.play_sound(filename, sink: nil, volume: nil) ⇒ void

This method returns an undefined value.

Play an audio file via openHAB sound service, Audio.playSound()

Examples:

Play an audio file

rule 'Play an audio file' do
  every :hour
  run { Audio.play_sound "beep.mp3", volume: 100 }
end

Parameters:

  • filename (String)

    The sound file to play

  • sink (String) (defaults to: nil)

    Specify a particular sink to output the speech

  • volume (PercentType) (defaults to: nil)

    Specify the volume for the speech



24
25
26
27
28
29
30
31
# File 'lib/openhab/core/actions/audio.rb', line 24

def play_sound(filename, sink: nil, volume: nil)
  volume = PercentType.new(volume) unless volume.is_a?(PercentType) || volume.nil?
  java_send :playSound,
            [java.lang.String, java.lang.String, PercentType.java_class],
            sink,
            filename.to_s,
            volume
end

.play_stream(url, sink: nil) ⇒ void

This method returns an undefined value.

Play an audio stream from an URL to the given sink(s). Set url to nil if streaming should be stopped

Examples:

Play an audio stream

Audio.play_stream 'example.com'

Parameters:

  • url (String)

    The URL of the audio stream

  • sink (String) (defaults to: nil)

    The audio sink, or nil to use the default audio sink



44
45
46
# File 'lib/openhab/core/actions/audio.rb', line 44

def play_stream(url, sink: nil)
  playStream(sink&.to_s, url)
end