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:
Using the lowercase equivalent works:
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.
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.NOTESare lowercase, and_to_freq()currently performs a case-sensitive dictionary lookup:As a result, note names using the capitalization shown in the documentation raise a
KeyError.Example
Current result:
Using the lowercase equivalent works:
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:
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.