docs » hs.sound
Load/play/manipulate sound files
- Functions - API calls offered directly by the extension
- getAudioEffectNames
- soundFileTypes
- soundTypes
- systemSounds
- Constructors - API calls which return an object, typically one that offers API methods
- getByFile
- getByName
- Methods - API calls which can only be made on an object returned by a constructor
- currentTime
- device
- duration
- isPlaying
- loopSound
- name
- pause
- play
- resume
- setCallback
- stop
- stopOnReload
- volume
Signature | hs.sound.getAudioEffectNames() -> table |
---|---|
Type | Function |
Description | Gets a table of installed Audio Units Effect names. |
Parameters |
|
Returns |
|
Notes |
|
Signature | hs.sound.soundFileTypes() -> table |
---|---|
Type | Function |
Description | Gets the supported sound file types |
Parameters |
|
Returns |
|
Notes |
|
Signature | hs.sound.soundTypes() -> table |
---|---|
Type | Function |
Description | Gets the supported UTI sound file formats |
Parameters |
|
Returns |
|
Signature | hs.sound.systemSounds() -> table |
---|---|
Type | Function |
Description | Gets a table of available system sounds |
Parameters |
|
Returns |
|
Notes |
|
Signature | hs.sound.getByFile(path) -> sound or nil |
---|---|
Type | Constructor |
Description | Creates an hs.sound object from a file |
Parameters |
|
Returns |
|
Signature | hs.sound.getByName(name) -> sound or nil |
---|---|
Type | Constructor |
Description | Creates an hs.sound object from a named sound |
Parameters |
|
Returns |
|
Notes |
|
| Signature | hs.sound:currentTime([seekTime]) -> soundObject | seconds
|
| -----------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| Type | Method |
| Description | Get or set the current seek offset within an hs.sound
object. |
| Parameters |
- seekTime - An optional number of seconds to seek to within the sound object
- If a parameter is provided, returns the sound object; otherwise returns the current position.
| Signature | hs.sound:device([deviceUID]) -> soundObject | UID string
|
| -----------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| Type | Method |
| Description | Get or set the playback device to use for an hs.sound
object |
| Parameters |
- deviceUID - An optional string containing the UID of an
hs.audiodevice
object to use for playback of this sound. Use an explicit nil to use the system's default device
- If a parameter is provided, returns the sound object; otherwise returns the current setting.
- To obtain the UID of a sound device, see
hs.audiodevice:uid()
Signature | hs.sound:duration() -> seconds |
---|---|
Type | Method |
Description | Gets the length of an hs.sound object |
Parameters |
|
Returns |
|
Signature | hs.sound:isPlaying() -> bool |
---|---|
Type | Method |
Description | Gets the current playback state of an hs.sound object |
Parameters |
|
Returns |
|
| Signature | hs.sound:loopSound([loop]) -> soundObject | bool
|
| -----------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| Type | Method |
| Description | Get or set the looping behaviour of an hs.sound
object |
| Parameters |
- loop - An optional boolean, true to loop playback, false to not loop
- If a parameter is provided, returns the sound object; otherwise returns the current setting.
- If you have registered a callback function for completion of a sound's playback, it will not be called when the sound loops
| Signature | hs.sound:name([soundName]) -> soundObject | name string
|
| -----------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| Type | Method |
| Description | Get or set the name of an hs.sound
object |
| Parameters |
- soundName - An optional string to use as the name of the object; use an explicit nil to remove the name
- If a parameter is provided, returns the sound object; otherwise returns the current setting.
- If remove the sound name by specifying
nil
, the sound will automatically be set to stop when Hammerspoon is reloaded.
| Signature | hs.sound:pause() -> soundObject | bool
|
| -----------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| Type | Method |
| Description | Pauses an hs.sound
object |
| Parameters |
- None
- The
hs.sound
object if the command was successful, otherwise false.
| Signature | hs.sound:play() -> soundObject | bool
|
| -----------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| Type | Method |
| Description | Plays an hs.sound
object |
| Parameters |
- None
- The
hs.sound
object if the command was successful, otherwise false.
| Signature | hs.sound:resume() -> soundObject | bool
|
| -----------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| Type | Method |
| Description | Resumes playing a paused hs.sound
object |
| Parameters |
- None
- The
hs.sound
object if the command was successful, otherwise false.
Signature | hs.sound:setCallback(function) -> soundObject |
---|---|
Type | Method |
Description | Set or remove the callback for receiving completion notification for the sound object. |
Parameters |
|
Returns |
|
Notes |
|
| Signature | hs.sound:stop() -> soundObject | bool
|
| -----------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| Type | Method |
| Description | Stops playing an hs.sound
object |
| Parameters |
- None
- The
hs.sound
object if the command was successful, otherwise false.
| Signature | hs.sound:stopOnReload([stopOnReload]) -> soundObject | bool
|
| -----------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| Type | Method |
| Description | Get or set whether a sound should be stopped when Hammerspoon reloads its configuration |
| Parameters |
- stopOnReload - An optional boolean, true to stop playback when Hammerspoon reloads its config, false to continue playback regardless. Defaults to true.
- If a parameter is provided, returns the sound object; otherwise returns the current setting.
- This method can only be used on a named
hs.sound
object, seehs.sound:name()
| Signature | hs.sound:volume([level]) -> soundObject | number
|
| -----------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| Type | Method |
| Description | Get or set the playback volume of an hs.sound
object |
| Parameters |
- level - A number between 0.0 and 1.0, representing the volume of the sound object relative to the current system volume
- If a parameter is provided, returns the sound object; otherwise returns the current value.