Bug 1162692 - Add SpeechSynthesisUtterance.chosenVoiceURI for testing purposes. r=smaug

This commit is contained in:
Eitan Isaacson 2015-05-12 13:24:58 -07:00
parent 9d09688122
commit e550c8cefd
11 changed files with 42 additions and 8 deletions

View File

@ -147,6 +147,12 @@ SpeechSynthesisUtterance::SetPitch(float aPitch)
mPitch = aPitch;
}
void
SpeechSynthesisUtterance::GetChosenVoiceURI(nsString& aResult) const
{
aResult = mChosenVoiceURI;
}
void
SpeechSynthesisUtterance::DispatchSpeechSynthesisEvent(const nsAString& aEventType,
uint32_t aCharIndex,

View File

@ -71,6 +71,8 @@ public:
void SetPitch(float aPitch);
void GetChosenVoiceURI(nsString& aResult) const;
enum {
STATE_NONE,
STATE_PENDING,
@ -107,6 +109,8 @@ private:
float mPitch;
nsString mChosenVoiceURI;
uint32_t mState;
bool mPaused;

View File

@ -25,7 +25,7 @@ async protocol PSpeechSynthesisRequest
__delete__(bool aIsError, float aElapsedTime, uint32_t aCharIndex);
OnStart();
OnStart(nsString aUri);
OnPause(float aElapsedTime, uint32_t aCharIndex);

View File

@ -73,9 +73,9 @@ SpeechSynthesisRequestChild::~SpeechSynthesisRequestChild()
}
bool
SpeechSynthesisRequestChild::RecvOnStart()
SpeechSynthesisRequestChild::RecvOnStart(const nsString& aUri)
{
mTask->DispatchStartImpl();
mTask->DispatchStartImpl(aUri);
return true;
}

View File

@ -48,7 +48,7 @@ public:
virtual ~SpeechSynthesisRequestChild();
protected:
virtual bool RecvOnStart() override;
virtual bool RecvOnStart(const nsString& aUri) override;
virtual bool Recv__delete__(const bool& aIsError,
const float& aElapsedTime,

View File

@ -120,10 +120,10 @@ SpeechSynthesisRequestParent::RecvCancel()
// SpeechTaskParent
nsresult
SpeechTaskParent::DispatchStartImpl()
SpeechTaskParent::DispatchStartImpl(const nsAString& aUri)
{
MOZ_ASSERT(mActor);
NS_ENSURE_TRUE(mActor->SendOnStart(), NS_ERROR_FAILURE);
NS_ENSURE_TRUE(mActor->SendOnStart(nsString(aUri)), NS_ERROR_FAILURE);
return NS_OK;
}

View File

@ -75,7 +75,7 @@ public:
SpeechTaskParent(float aVolume, const nsAString& aUtterance)
: nsSpeechTask(aVolume, aUtterance) {}
virtual nsresult DispatchStartImpl();
virtual nsresult DispatchStartImpl(const nsAString& aUri);
virtual nsresult DispatchEndImpl(float aElapsedTime, uint32_t aCharIndex);

View File

@ -140,6 +140,12 @@ nsSpeechTask::BindStream(ProcessedMediaStream* aStream)
mPort = aStream->AllocateInputPort(mStream, 0);
}
void
nsSpeechTask::SetChosenVoiceURI(const nsAString& aUri)
{
mChosenVoiceURI = aUri;
}
NS_IMETHODIMP
nsSpeechTask::Setup(nsISpeechTaskCallback* aCallback,
uint32_t aChannels, uint32_t aRate, uint8_t argc)
@ -281,6 +287,12 @@ nsSpeechTask::DispatchStart()
nsresult
nsSpeechTask::DispatchStartImpl()
{
return DispatchStartImpl(mChosenVoiceURI);
}
nsresult
nsSpeechTask::DispatchStartImpl(const nsAString& aUri)
{
LOG(PR_LOG_DEBUG, ("nsSpeechTask::DispatchStart"));
@ -289,6 +301,7 @@ nsSpeechTask::DispatchStartImpl()
NS_ERROR_NOT_AVAILABLE);
mUtterance->mState = SpeechSynthesisUtterance::STATE_SPEAKING;
mUtterance->mChosenVoiceURI = aUri;
mUtterance->DispatchSpeechSynthesisEvent(NS_LITERAL_STRING("start"), 0, 0,
NS_LITERAL_STRING(""));

View File

@ -47,10 +47,14 @@ public:
void BindStream(ProcessedMediaStream* aStream);
void SetChosenVoiceURI(const nsAString& aUri);
protected:
virtual ~nsSpeechTask();
virtual nsresult DispatchStartImpl();
nsresult DispatchStartImpl();
virtual nsresult DispatchStartImpl(const nsAString& aUri);
virtual nsresult DispatchEndImpl(float aElapsedTime, uint32_t aCharIndex);
@ -89,6 +93,8 @@ private:
nsRefPtr<SpeechSynthesis> mSpeechSynthesis;
bool mIndirectAudio;
nsString mChosenVoiceURI;
};
} // namespace dom

View File

@ -567,6 +567,8 @@ nsSynthVoiceRegistry::Speak(const nsAString& aText,
return;
}
aTask->SetChosenVoiceURI(voice->mUri);
LOG(PR_LOG_DEBUG, ("nsSynthVoiceRegistry::Speak - Using voice URI: %s",
NS_ConvertUTF16toUTF8(voice->mUri).get()));

View File

@ -28,4 +28,7 @@ interface SpeechSynthesisUtterance : EventTarget {
attribute EventHandler onresume;
attribute EventHandler onmark;
attribute EventHandler onboundary;
[ChromeOnly]
readonly attribute DOMString chosenVoiceURI;
};