Title: [144392] trunk/Source/WebCore
- Revision
- 144392
- Author
- [email protected]
- Date
- 2013-02-28 16:21:46 -0800 (Thu, 28 Feb 2013)
Log Message
WebSpeech: support pitch change
https://bugs.webkit.org/show_bug.cgi?id=107348
Reviewed by Beth Dakin.
Implement a policy for the Mac synthesizer to convert from the utterance's pitch rate
to something sensible for the platform.
* platform/mac/PlatformSpeechSynthesizerMac.mm:
(-[WebSpeechSynthesisWrapper initWithSpeechSynthesizer:WebCore::]):
(-[WebSpeechSynthesisWrapper convertPitchToNSSpeechValue:]):
(-[WebSpeechSynthesisWrapper updateBasePitchForSynthesizer]):
(-[WebSpeechSynthesisWrapper speakUtterance:WebCore::]):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (144391 => 144392)
--- trunk/Source/WebCore/ChangeLog 2013-03-01 00:19:39 UTC (rev 144391)
+++ trunk/Source/WebCore/ChangeLog 2013-03-01 00:21:46 UTC (rev 144392)
@@ -1,3 +1,19 @@
+2013-02-28 Chris Fleizach <[email protected]>
+
+ WebSpeech: support pitch change
+ https://bugs.webkit.org/show_bug.cgi?id=107348
+
+ Reviewed by Beth Dakin.
+
+ Implement a policy for the Mac synthesizer to convert from the utterance's pitch rate
+ to something sensible for the platform.
+
+ * platform/mac/PlatformSpeechSynthesizerMac.mm:
+ (-[WebSpeechSynthesisWrapper initWithSpeechSynthesizer:WebCore::]):
+ (-[WebSpeechSynthesisWrapper convertPitchToNSSpeechValue:]):
+ (-[WebSpeechSynthesisWrapper updateBasePitchForSynthesizer]):
+ (-[WebSpeechSynthesisWrapper speakUtterance:WebCore::]):
+
2013-02-28 Vineet Chaudhary <[email protected]>
Unreviewed. Bindings test results update after r144376.
Modified: trunk/Source/WebCore/platform/mac/PlatformSpeechSynthesizerMac.mm (144391 => 144392)
--- trunk/Source/WebCore/platform/mac/PlatformSpeechSynthesizerMac.mm 2013-03-01 00:19:39 UTC (rev 144391)
+++ trunk/Source/WebCore/platform/mac/PlatformSpeechSynthesizerMac.mm 2013-03-01 00:21:46 UTC (rev 144392)
@@ -40,6 +40,7 @@
const WebCore::PlatformSpeechSynthesisUtterance* m_utterance;
RetainPtr<NSSpeechSynthesizer> m_synthesizer;
+ float m_basePitch;
}
- (WebSpeechSynthesisWrapper *)initWithSpeechSynthesizer:(WebCore::PlatformSpeechSynthesizer *)synthesizer;
@@ -55,6 +56,7 @@
return nil;
m_synthesizerObject = synthesizer;
+ [self updateBasePitchForSynthesizer];
return self;
}
@@ -66,6 +68,19 @@
return 200.0f * rate;
}
+- (float)convertPitchToNSSpeechValue:(float)pitch
+{
+ // This allows the base pitch to range from 0% - 200% of the normal pitch.
+ return m_basePitch * pitch;
+}
+
+- (void)updateBasePitchForSynthesizer
+{
+ // Reset the base pitch whenever we change voices, since the base pitch is different for each voice.
+ [m_synthesizer setObject:nil forProperty:NSSpeechResetProperty error:nil];
+ m_basePitch = [[m_synthesizer objectForProperty:NSSpeechPitchBaseProperty error:nil] floatValue];
+}
+
- (void)speakUtterance:(const WebCore::PlatformSpeechSynthesisUtterance *)utterance
{
// When speak is called we should not have an existing speech utterance outstanding.
@@ -108,9 +123,17 @@
// Don't set the voice unless necessary. There's a bug in NSSpeechSynthesizer such that
// setting the voice for the first time will cause the first speechDone callback to report it was unsuccessful.
- if (![[m_synthesizer voice] isEqualToString:voiceURI])
+ BOOL updatePitch = NO;
+ if (![[m_synthesizer voice] isEqualToString:voiceURI]) {
[m_synthesizer setVoice:voiceURI];
+ // Reset the base pitch whenever we change voices.
+ updatePitch = YES;
+ }
+ if (m_basePitch == 0 || updatePitch)
+ [self updateBasePitchForSynthesizer];
+
+ [m_synthesizer setObject:[NSNumber numberWithFloat:[self convertPitchToNSSpeechValue:utterance->pitch()]] forProperty:NSSpeechPitchBaseProperty error:nil];
[m_synthesizer setRate:[self convertRateToWPM:utterance->rate()]];
[m_synthesizer setVolume:utterance->volume()];
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes