Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Sapi4 pitch change #12311 #12354

Merged
merged 5 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
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
35 changes: 34 additions & 1 deletion source/synthDrivers/sapi4.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import nvwave
import weakref

from speech.commands import PitchCommand
from speech.commands import IndexCommand, SpeechCommand, CharacterModeCommand

class SynthDriverBufSink(COMObject):
Expand Down Expand Up @@ -115,6 +116,11 @@ def speak(self,speechSequence):
textList=[]
charMode=False
item=None
isPitchCommand = False
pitch = WORD()
self._ttsAttrs.PitchGet(byref(pitch))
oldPitch = pitch.value

for item in speechSequence:
if isinstance(item,str):
textList.append(item.replace('\\','\\\\'))
Expand All @@ -123,6 +129,16 @@ def speak(self,speechSequence):
elif isinstance(item, CharacterModeCommand):
textList.append("\\RmS=1\\" if item.state else "\\RmS=0\\")
charMode=item.state
elif isinstance(item, PitchCommand):
offset = int(config.conf["speech"]['sapi4']["capPitchChange"])
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was looking at this code and this really feels incorrect to me. It looks like the caps pitch change is applied to every pitch change, regardless of whether it is related to capital letters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I see you've opened a PR to try and fix this, that's great.

offset = int((self._maxPitch - self._minPitch) * offset / 100)
val = oldPitch + offset
if val > self._maxPitch:
val = self._maxPitch
if val < self._minPitch:
val = self._minPitch
self._ttsAttrs.PitchSet(val)
isPitchCommand = True
elif isinstance(item, SpeechCommand):
log.debugWarning("Unsupported speech command: %s"%item)
else:
Expand All @@ -139,7 +155,24 @@ def speak(self,speechSequence):
textList.append("\\PAU=1\\")
text="".join(textList)
flags=TTSDATAFLAG_TAGGED
self._ttsCentral.TextData(VOICECHARSET.CHARSET_TEXT, flags,TextSDATA(text),self._bufSinkPtr,ITTSBufNotifySink._iid_)
if isPitchCommand:
self._ttsCentral.TextData(
VOICECHARSET.CHARSET_TEXT,
flags,
TextSDATA(text),
self._bufSinkPtr,
ITTSBufNotifySink._iid_
)
self._ttsAttrs.PitchSet(oldPitch)
isPitchCommand = False
else:
self._ttsCentral.TextData(
VOICECHARSET.CHARSET_TEXT,
flags,
TextSDATA(text),
self._bufSinkPtr,
ITTSBufNotifySink._iid_
)

def cancel(self):
self._ttsCentral.AudioReset()
Expand Down
1 change: 1 addition & 0 deletions user_docs/en/changes.t2t
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ What's New in NVDA
- Strikethrough, superscript and subscript formatting for entire Excel cells are now reported if the corresponding option is enabled. (#12264)
- Fixed copying config during installation from a portable copy when default destination config directory is empty. (#12071, #12205)
- Fixed incorrect announcement of some letters with accents or diacritic when 'Say cap before capitals' option is checked. (#11948)
- Fixed the pitch change failure in Sapi4 speech synthesizer. (#12311)


== Changes for Developers ==
Expand Down