Skip to content

Speaker.play() documentation uses uppercase note names but the implementation only accepts lowercase #152

Description

@owasikohu

Speaker.play() documentation uses uppercase note names but the implementation only accepts lowercase

Description

The documentation for Speaker.play() shows uppercase note names such as "E4" and ["E4", 2].

However, the keys in Speaker.NOTES are lowercase, and _to_freq() currently performs a case-sensitive dictionary lookup:

if type(freq) is str:
    return int(self.NOTES[freq])

As a result, note names using the capitalization shown in the documentation raise a KeyError.

Example

from picozero import Speaker

speaker = Speaker(5)
speaker.play("E4")

Current result:

KeyError: 'E4'

Using the lowercase equivalent works:

speaker.play("e4")

Expected behavior

The note names shown in the documentation, such as "E4", should work.

Possible fix

One possible solution would be to normalize string note names before looking them up:

return int(self.NOTES[freq.lower()])

This would preserve the existing lowercase behavior while also allowing uppercase or mixed-case note names.

Alternatively, if lowercase-only note names are intentional, the examples in the documentation could be changed to lowercase.

I would be happy to submit a pull request with the implementation change and a regression test if accepting note names case-insensitively is the preferred behavior.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions