mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1191814 - WebSpeech synthesis API and AudioChannelService, r=eeejay
This commit is contained in:
parent
79abdcd746
commit
259a723567
@ -23,6 +23,8 @@ async protocol PSpeechSynthesisRequest
|
||||
|
||||
ForceEnd();
|
||||
|
||||
SetAudioOutputVolume(uint32_t aVolume);
|
||||
|
||||
child:
|
||||
|
||||
__delete__(bool aIsError, float aElapsedTime, uint32_t aCharIndex);
|
||||
|
@ -191,5 +191,13 @@ SpeechTaskChild::ForceEnd()
|
||||
mActor->SendForceEnd();
|
||||
}
|
||||
|
||||
void
|
||||
SpeechTaskChild::SetAudioOutputVolume(uint32_t aVolume)
|
||||
{
|
||||
if (mActor) {
|
||||
mActor->SendSetAudioOutputVolume(aVolume);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -92,6 +92,8 @@ public:
|
||||
|
||||
virtual void ForceEnd() override;
|
||||
|
||||
virtual void SetAudioOutputVolume(uint32_t aVolume) override;
|
||||
|
||||
private:
|
||||
SpeechSynthesisRequestChild* mActor;
|
||||
};
|
||||
|
@ -127,6 +127,14 @@ SpeechSynthesisRequestParent::RecvForceEnd()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SpeechSynthesisRequestParent::RecvSetAudioOutputVolume(const uint32_t& aVolume)
|
||||
{
|
||||
MOZ_ASSERT(mTask);
|
||||
mTask->SetAudioOutputVolume(aVolume);
|
||||
return true;
|
||||
}
|
||||
|
||||
// SpeechTaskParent
|
||||
|
||||
nsresult
|
||||
|
@ -69,6 +69,8 @@ protected:
|
||||
virtual bool RecvCancel() override;
|
||||
|
||||
virtual bool RecvForceEnd() override;
|
||||
|
||||
virtual bool RecvSetAudioOutputVolume(const uint32_t& aVolume) override;
|
||||
};
|
||||
|
||||
class SpeechTaskParent : public nsSpeechTask
|
||||
|
@ -4,10 +4,12 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "AudioChannelAgent.h"
|
||||
#include "AudioChannelService.h"
|
||||
#include "AudioSegment.h"
|
||||
#include "nsSpeechTask.h"
|
||||
#include "SpeechSynthesis.h"
|
||||
#include "nsSynthVoiceRegistry.h"
|
||||
#include "SpeechSynthesis.h"
|
||||
|
||||
// GetCurrentTime is defined in winbase.h as zero argument macro forwarding to
|
||||
// GetTickCount() and conflicts with nsSpeechTask::GetCurrentTime().
|
||||
@ -89,6 +91,7 @@ NS_IMPL_CYCLE_COLLECTION(nsSpeechTask, mSpeechSynthesis, mUtterance, mCallback);
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsSpeechTask)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISpeechTask)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIAudioChannelAgentCallback)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISpeechTask)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
@ -314,6 +317,8 @@ nsSpeechTask::DispatchStart()
|
||||
nsresult
|
||||
nsSpeechTask::DispatchStartInner()
|
||||
{
|
||||
CreateAudioChannelAgent();
|
||||
|
||||
nsSynthVoiceRegistry::GetInstance()->SetIsSpeaking(true);
|
||||
return DispatchStartImpl();
|
||||
}
|
||||
@ -356,6 +361,8 @@ nsSpeechTask::DispatchEnd(float aElapsedTime, uint32_t aCharIndex)
|
||||
nsresult
|
||||
nsSpeechTask::DispatchEndInner(float aElapsedTime, uint32_t aCharIndex)
|
||||
{
|
||||
DestroyAudioChannelAgent();
|
||||
|
||||
if (!mPreCanceled) {
|
||||
nsSynthVoiceRegistry::GetInstance()->SpeakNext();
|
||||
}
|
||||
@ -645,5 +652,53 @@ nsSpeechTask::SetSpeechSynthesis(SpeechSynthesis* aSpeechSynthesis)
|
||||
mSpeechSynthesis = aSpeechSynthesis;
|
||||
}
|
||||
|
||||
void
|
||||
nsSpeechTask::CreateAudioChannelAgent()
|
||||
{
|
||||
if (!mUtterance) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mAudioChannelAgent) {
|
||||
mAudioChannelAgent->NotifyStoppedPlaying(nsIAudioChannelAgent::AUDIO_AGENT_NOTIFY);
|
||||
}
|
||||
|
||||
mAudioChannelAgent = new AudioChannelAgent();
|
||||
mAudioChannelAgent->InitWithWeakCallback(mUtterance->GetOwner(),
|
||||
static_cast<int32_t>(AudioChannelService::GetDefaultAudioChannel()),
|
||||
this);
|
||||
}
|
||||
|
||||
void
|
||||
nsSpeechTask::DestroyAudioChannelAgent()
|
||||
{
|
||||
if (mAudioChannelAgent) {
|
||||
mAudioChannelAgent->NotifyStoppedPlaying(nsIAudioChannelAgent::AUDIO_AGENT_NOTIFY);
|
||||
mAudioChannelAgent = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSpeechTask::WindowVolumeChanged(float aVolume, bool aMuted)
|
||||
{
|
||||
SetAudioOutputVolume(mVolume * aVolume * aMuted);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSpeechTask::WindowAudioCaptureChanged()
|
||||
{
|
||||
// This is not supported yet.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsSpeechTask::SetAudioOutputVolume(uint32_t aVolume)
|
||||
{
|
||||
if (mStream) {
|
||||
mStream->SetAudioOutputVolume(this, aVolume);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "MediaStreamGraph.h"
|
||||
#include "SpeechSynthesisUtterance.h"
|
||||
#include "nsIAudioChannelAgent.h"
|
||||
#include "nsISpeechService.h"
|
||||
|
||||
namespace mozilla {
|
||||
@ -19,6 +20,7 @@ class SpeechSynthesis;
|
||||
class SynthStreamListener;
|
||||
|
||||
class nsSpeechTask : public nsISpeechTask
|
||||
, public nsIAudioChannelAgentCallback
|
||||
{
|
||||
friend class SynthStreamListener;
|
||||
|
||||
@ -27,6 +29,7 @@ public:
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsSpeechTask, nsISpeechTask)
|
||||
|
||||
NS_DECL_NSISPEECHTASK
|
||||
NS_DECL_NSIAUDIOCHANNELAGENTCALLBACK
|
||||
|
||||
explicit nsSpeechTask(SpeechSynthesisUtterance* aUtterance);
|
||||
nsSpeechTask(float aVolume, const nsAString& aText);
|
||||
@ -49,6 +52,8 @@ public:
|
||||
|
||||
void SetChosenVoiceURI(const nsAString& aUri);
|
||||
|
||||
virtual void SetAudioOutputVolume(uint32_t aVolume);
|
||||
|
||||
bool IsPreCanceled()
|
||||
{
|
||||
return mPreCanceled;
|
||||
@ -102,12 +107,18 @@ private:
|
||||
|
||||
nsresult DispatchEndInner(float aElapsedTime, uint32_t aCharIndex);
|
||||
|
||||
void CreateAudioChannelAgent();
|
||||
|
||||
void DestroyAudioChannelAgent();
|
||||
|
||||
nsRefPtr<SourceMediaStream> mStream;
|
||||
|
||||
nsRefPtr<MediaInputPort> mPort;
|
||||
|
||||
nsCOMPtr<nsISpeechTaskCallback> mCallback;
|
||||
|
||||
nsCOMPtr<nsIAudioChannelAgent> mAudioChannelAgent;
|
||||
|
||||
uint32_t mChannels;
|
||||
|
||||
nsRefPtr<SpeechSynthesis> mSpeechSynthesis;
|
||||
|
Loading…
Reference in New Issue
Block a user