Skip to content

Commit

Permalink
Fix Sapi4 pitch change (PR #12354)
Browse files Browse the repository at this point in the history
Fixes: #12311

Co-authored-by: Reef Turner <[email protected]>
  • Loading branch information
cary-rowen and feerrenrut authored Apr 30, 2021
1 parent e2d2696 commit a3af16e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
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"])
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

0 comments on commit a3af16e

Please sign in to comment.