Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions source/nvwave.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
c_void_p,
CFUNCTYPE,
c_float,
string_at,
c_char_p,
cast,
)
from comtypes import HRESULT
from comtypes.hresult import E_INVALIDARG
Expand Down Expand Up @@ -339,12 +340,13 @@ def feed(
# turn off trimming temporarily.
if self._purpose is AudioPurpose.SPEECH and self._isLeadingSilenceInserted:
self.startTrimmingLeadingSilence(False)
if not isinstance(data, bytes):
data = string_at(data, size)
# wasPlay_feed requires c_char_p, so cast data to c_char_p before calling.
# Casting bytes to c_char_p is also fine, as long as the original data is not released.
dataptr = cast(data, c_char_p)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there a reason not to perform this cast directly in the call to wasapi.wasPlay_feed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

See comment from @LeonarddeR :

I think it's better to keep the cast out of the wasPlay_feed call, otherwise it is hard to track issues caused by cast failures.

try:
wasapi.wasPlay_feed(
self._player,
data,
dataptr,
size if size is not None else len(data),
byref(feedId) if onDone else None,
)
Expand Down
Loading