Repository navigation
Python: Encode text before passing it to speak_to_memory - #163
Merged
ethindp merged 1 commit intoOct 22, 2026
Merged
Conversation
Backend.speak_to_memory passed the str straight to cffi, which needs bytes for a const char *, so every call raised TypeError before it reached the backend. speak, braille and output already encode to UTF-8. The test uses a custom backend so it runs without a speech engine. Ruff flags pytest's assert as S101, so that rule is ignored under tests/. Signed-off-by: Miguel Ángel Insfrán <[email protected]>
Owner
|
Thank you for this! We don't run pytest since we don't really have any tests (since tests for Prism is rather difficult to do even with custom backends). If you want, feel free to have pytest run given that this regression test now exists. |
Contributor
Author
|
Thanks! I'd rather keep this PR to the encoding fix only. I can open a separate PR that adds a pytest step to CI so the regression test runs. Is this one okay to merge as it is? |
Owner
|
@miguel-cinsfran I would prefer that this include a regression test, as to avoid an unnecessary PR. However, if you truly wish not to include one, then yes, this PR is ready for merge. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backend.speak_to_memoryin the Python bindings passestexttoprism_backend_speak_to_memoryas astr. cffi needsbytesfor aconst char *, so every call fails before it reaches the backend:speak,brailleandoutputalready calltext.encode("utf-8"). This does the same.Tested on Windows 11 (x64) with Python 3.11 and the prismatoid 0.18.3 wheel, whose bindings are the same as master's. With SAPI and OneCore, both raise the
TypeErrorbefore the change. After it, both deliver 16 kHz mono audio to the callback, and the rate and voice set on the backend apply to it.The regression test in
tests/python/registers a custom backend, so it doesn't need a speech engine. It fails on master with the sameTypeErrorand passes with this change. I didn't find an existing place for Python tests, so the folder is new; if you'd rather have it somewhere else, I'll move it. Ruff flags pytest'sassertasS101, sopyproject.tomlignores that rule undertests/. CI doesn't seem to run pytest, so I ran it locally.ruff check .passes.