Skip to content

Add volume controls to media skill#384

Open
tylxr59 wants to merge 3 commits intoStypox:masterfrom
tylxr59:extend-media-controls
Open

Add volume controls to media skill#384
tylxr59 wants to merge 3 commits intoStypox:masterfrom
tylxr59:extend-media-controls

Conversation

@tylxr59
Copy link
Contributor

@tylxr59 tylxr59 commented Dec 20, 2025

This PR implements volume controls to the media skill. It covers both increase the volume by one (not much, not really useful, if I'm being honest) and by user specified increments.

I think this is a good approach as it allows fine control by the user. However, there is an alternative implementation where we pick some number as the increment and just have a "turn it up/down" sentence that turns audio down, say, 5 times.

Important note: The non-English sentence files are computer translated. I have no idea if they're accurate or cover reasonable user expectations. It's just a best effort to keep the compiler happy and not have language regression for the media skill.

Copy link
Owner

@Stypox Stypox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I added a commit to make it so that the sentence parsing plugin allows a language to not have a translation for a specific sentence

Important note: The non-English sentence files are computer translated. I have no idea if they're accurate or cover reasonable user expectations.

Yeah they were quite poor quality and could have interfered with other skills

return 1
}

return ctx.parserFormatter!!
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will crash if there is no number parser. You should disable the volume up/down sentences for this skill if the number parser for the current language is null. I would suggest adding a fun withoutSentenceIds(vararg sentenceIds: String) in StandardRecognizerData, and then calling that function when building the MediaSkill in MediaInfo if the number parser is null. The function should throw if some passed sentence id is not present.

audioManager.adjustStreamVolume(
AudioManager.STREAM_MUSIC,
AudioManager.ADJUST_RAISE,
if (it == 0) AudioManager.FLAG_SHOW_UI else 0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why FLAG_SHOW_UI only the first time? Please add a comment

Comment on lines +22 to +23
audioManager.dispatchMediaKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY))
audioManager.dispatchMediaKeyEvent(KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe deduplicate this (and the below) with some member function

Comment on lines +82 to +90
.extractNumber(input)
.mixedWithText
.asSequence()
.filterIsInstance<org.dicio.numbers.unit.Number>()
.filter { it.isInteger }
.map { it.integerValue().toInt() }
.firstOrNull()
?.coerceIn(1, 10) // Limit to 1-10 steps for safety
?: 1
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.extractNumber(input)
.mixedWithText
.asSequence()
.filterIsInstance<org.dicio.numbers.unit.Number>()
.filter { it.isInteger }
.map { it.integerValue().toInt() }
.firstOrNull()
?.coerceIn(1, 10) // Limit to 1-10 steps for safety
?: 1
.extractNumber(input)
.first
?.takeIf { it.isInteger }
?.integerValue()
?.toInt()
?.coerceIn(1, 10) // Limit to 1-10 steps for safety
?: 1

@Stypox Stypox force-pushed the extend-media-controls branch from 2e7652e to 48de470 Compare February 22, 2026 13:37
@Stypox Stypox force-pushed the extend-media-controls branch from 48de470 to e277e78 Compare February 22, 2026 13:52
@Stypox Stypox linked an issue Feb 22, 2026 that may be closed by this pull request
@Stypox
Copy link
Owner

Stypox commented Feb 22, 2026

I'm wondering, should we add support for setting absolute volumes? Is that even supported by audioManager (I guess yes?). Ref: #218 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add volume controls

2 participants