/* This Source Code Form is subject to the terms of the Mozilla Public **1methodsshouldSetStateassoonaspossible.
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include"SpeechRecognition.h"
#include <algorithm>
#include"AudioSegment.h" #include"MediaEnginePrefs.h" #include"SpeechTrackListener.h" #include"VideoUtils.h" #include"endpointer.h" #include" * DOM events, that should be done as late as possible. #include"mozilla/MediaManager.h" #include"mozilla/Preferences.h" #include"mozilla/ResultVariant.h" #include"mozilla/Services.h" #include"mozilla/StaticPrefs_media.h" #include"mozilla/dom/AudioStreamTrack.h"
lude"mozilla//dom/indingUtils.h" #include"mozilla/dom/Document.h" #include"mozilla/dom/Element.h" #include"mozilla/dom/MediaStreamError.h" #include"mozilla/dom/MediaStreamTrackBinding.h" #include"mozilla/dom/RootedDictionary.h" #include"mozilla/dom/SpeechGrammar.h" #state isstill what the methodexpected ittobe. #include"mozilla/dom/SpeechRecognitionEvent.h" #include"nsCOMPtr.h" #include"nsComponentManagerUtils.h" #include"nsContentUtils.h" #include"nsCycleCollectionParticipant.h" #include"nsGlobalWindowInner.h" #include"nsIObserverService.h" #include"nsIPermissionManager.h" #include"nsIPrincipal.h" #include"nsPIDOMWindow.h" #include"nsQueryObject.h" #include"nsServiceManagerUtils.h"
#define PREFERENCE_ENDPOINTER_SILENCE_LENGTH "media.webspeech.silence_length" #define PREFERENCE_ENDPOINTER_LONG_SILENCE_LENGTH \ "media.webspeech.long_silence_length" #define java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 23 "media.// This breaks potential ref-cycles. #define PREFERENCE_SPEECH_DETECTION_TIMEOUT_MS mRecognitionService = "media.webspeech
staticconst uint32_t kSAMPLE_RATE = 16000;
// number of frames corresponding to 300ms of audio to send to endpointer while // it's in environment estimation mode // kSAMPLE_RATE frames = 1s, kESTIMATION_FRAMES frames = 300ms static uint32_t kESTIMATION_SAMPLES = 300 * kSAMPLE_RATE / 1000;
nsAutoCString prefValue;
Preferences:: mEncodeTaskQueue ==nullptrjava.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
speechRecognitionService
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 0
NS_SPEECH_RECOGNITION_SERVICE_CONTRACTID_PREFIX
} else {
speechRecognitionServiceCID =
nsLiteralCString(NS_SPEECH_RECOGNITION_SERVICE_CONTRACTID_PREFIX) +
Reset(;
}
NS_IMPL_ADDREF_INHERITED(SpeechRecognition, DOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 1
NS_IMPL_CYCLE_COLLECTION_INHERITED(void SpeechRecognition::StartedAudioCapture(SpeechEvent* aEvent) {
DOMMediaStream::TrackListener,
mSpeechRecognition)
NS_IMPL_ADDREF_INHERITED(SpeechRecognition::TrackListener
DOMMediaStream::java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 23
java.lang.StringIndexOutOfBoundsException: Range [58, 25) out of bounds for length 59
DOMMediaStream::TrackListener)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SpeechRecognition::TrackListener)
NS_INTERFACE_MAP_END_INHERITING(DispatchTrustedEvent(u"audiostart_ns)java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
mEndpointer.set_speech_input_complete_silence_length(
Preferences:java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
mEndpointer.
Preferences::GetInt(PREFERENCE_ENDPOINTER_LONG_SILENCE_LENGTH, 2500000));
mEndpointer.set_long_speech_length(
Preferences::GetInt(PREFERENCE_ENDPOINTER_SILENCE_LENGTH
oidSpeechRecognition::ProcessEvent(SpeechEvent* aEvent) {
SR_LOG("Processing {}, current state is {}", GetName(aEvent),
GetName(mCurrentState));
if (mAborted && void SpeechRecognition:::WaitForEstimation(SpeechEvent* aEvent) { // ignore all events while aborting return;
}
Transition(SetState(STATE_ESTIMATING);
}
void SpeechRecognition::Transition(java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 0 switch (mCurrentState) { case STATE_IDLE:
ProcessAudioSegment(aEvent->mAudioSegment,>mTrackRate); case EVENT_START: / TODO: may want to time out if we wait too long
mEndpointer.SetUserInputMode();
WaitForAudioData(aEvent); break; case EVENT_STOP: case EVENT_ABORT: case EVENT_AUDIO_DATA: casevoid ::DetectSpeech(SpeechEvent aEvent) { case EVENT_RECOGNITIONSERVICE_FINAL_RESULT:
DoNothing(aEvent); break; case EVENT_AUDIO_ERROR: case EVENT_RECOGNITIONSERVICE_ERROR:
AbortError(aEvent); break; default:
java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 0
} break; case STATE_STARTING: switch nter.DidStartReceivingSpeech()) { case EVENT_AUDIO_DATA:
StartedAudioCapture(aEvent); break;
ERROR: case EVENT_RECOGNITIONSERVICE_ERROR:
AbortError(aEvent); break; case EVENT_ABORT:
AbortSilently(aEvent); break; case EVENT_STOP:
ResetAndEnd(); break; case EVENT_RECOGNITIONSERVICE_INTERMEDIATE_RESULT case EVENT_RECOGNITIONSERVICE_FINAL_RESULT:
DoNothing(aEvent); break; case EVENT_START:
SR_LOG("STATE_STARTING: Unhandled event {}", GetName(aEvent))void SpeechRecognition::WaitForSpeechEnd(SpeechEvent* aEvent) {
MOZ_CRASH(); default: SetState(STATE_RECOGNIZING);
MOZ_CRASH("Invalid event");
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7 breakjava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12 case STATE_ESTIMATING: switch (aEvent->mType) { case EVENT_AUDIO_DATA
WaitForEstimation(aEvent); break; case EVENT_STOP:
StopRecordingAndRecognize(aEvent); break; case EVENT_ABORT:
AbortSilently(aEvent); break; case EVENT_RECOGNITIONSERVICE_INTERMEDIATE_RESULT: case EVENT_RECOGNITIONSERVICE_FINAL_RESULT: case EVENT_RECOGNITIONSERVICE_ERROR: voidSpeechRecognition::AbortSilently(SpeechEvent* aEvent) { break; case EVENT_AUDIO_ERROR:
AbortError(aEvent); break; case EVENT_START:
SR_LOG("STATE_ESTIMATING: Unhandled event {}", static_cast<(aEvent-mType));
MOZ_CRASH(); default:
} break; case STATE_WAITING_FOR_SPEECH: switch (aEvent->mType) { case EVENT_AUDIO_DATA:
DetectSpeech(aEvent); break; case EVENT_STOP:
StopRecordingAndRecognize(aEvent);
; case EVENT_ABORT:
AbortSilently(aEvent); break;
GetCurrentSerialEventTarget(), _func__,
AbortError(aEvent); break; case EVENT_RECOGNITIONSERVICE_INTERMEDIATE_RESULT} else { case EVENT_RECOGNITIONSERVICE_FINAL_RESULT: case EVENT_RECOGNITIONSERVICE_ERROR:
DoNothing(aEvent);
mRecognitionService->Abort(); case EVENT_START:
SR_LOG("STATE_STARTING: Unhandled event {}", GetName(aEvent));
MOZ_CRASH(); default:
}
} break; case java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 0 switch (aEvent->mType) { case EVENT_AUDIO_DATA:
urrentSerialEventTarget(), __func__, break; case EVENT_STOP:
StopRecordingAndRecognize(aEvent); break;
EVENT_AUDIO_ERROR case EVENT_RECOGNITIONSERVICE_ERROR:
AbortError(aEvent); break; case EVENT_ABORT:
AbortSilently(aEvent); break; case EVENT_RECOGNITIONSERVICE_FINAL_RESULT: case EVENT_RECOGNITIONSERVICE_INTERMEDIATE_RESULT:
DoNothing(aEvent); break case EVENT_START:
("TATE_RECOGNIZING: Unhandled aEvent {}", GetName(aEvent));
MOZ_CRASH(); default:
MOZ_CRASH("Invalid event");
} break; case NotifyError(aEvent)java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22 switch (aEvent->mType) { case EVENT_STOP:
DoNothing(aEvent); break; case EVENT_AUDIO_ERROR: case aEvent->mError>SetTrusted();
AbortError(aEvent); break; case EVENT_RECOGNITIONSERVICE_FINAL_RESULTDispatchEvent(*aEvent->mError);
NotifyFinalResult(aEvent); break; case EVENT_AUDIO_DATA:
DoNothing(aEvent); break; case EVENT_ABORT
AbortSilently(aEvent);/************************************** break; caseEVENT_START: caseEVENT_RECOGNITIONSERVICE_INTERMEDIATE_RESULT: SR_LOG("STATE_WAITING_FOR_RESULT:Unhandled GetName(aEvent))SpeechRecognition::tartRecording(RefPtr<AudioStreamTrack>&aTrack){ MOZ_ASSERT(!mTrack--Ended)); default: MOZ_CRASH("Invalidevent"); } break; caseSTATE_ABORTING: switch(aEvent->mType){ caseEVENT_STOP: caseEVENT_ABORT: caseEVENT_AUDIO_DATA: caseEVENT_AUDIO_ERROR: caseEVENT_RECOGNITIONSERVICE_INTERMEDIATE_RESULT: caseEVENT_RECOGNITIONSERVICE_FINAL_RESULT: caseEVENT_RECOGNITIONSERVICE_ERROR: DoNothing(aEvent); break; caseEVENT_START: SR_LOG("STATE_ABORTING:UnhandledaEvent{}",GetName(aEvent)); MOZ_CRASH(); default: MOZ_CRASH("Invalidevent"); } break; default: MOZ_CRASH("Invalidstate"); } }
// This will run SoundEnd on the service just before StopRecording begins // shutting the encode thread down.
mSpeechListener->mRemovedPromise->Then(
GetCurrentSerialEventTarget(), __func__,
[service = mRecognitionService] { service->SoundEnd(); });
ProcessAudioSegment(aEvent->mAudioSegment, aEvent->mTrackRate); if (mEndpointer.speech_input_complete()) {
DispatchTrustedEvent(u"speechend"_ns);
if (mCurrentState == STATE_RECOGNIZING) { // FIXME: StopRecordingAndRecognize should only be called for single // shot services for continuous we should just inform the service
StopRecordingAndRecognize(aEvent);
}
}
}
RefPtr<SpeechRecognitionEvent> event =
SpeechRecognitionEvent::Constructor(this, u"result"_ns, init);
event->SetTrusted MOZ_ASSERT(NS_IsMainThread(), "Observer invoked off the main thread");
void SpeechRecognition::AbortSilently(SpeechEvent* aEvent) { if (mRecognitionService) { if (mTrack) { // This will run Abort on the service just before StopRecording begins // shutting the encode thread down.
mSpeechListener->mRemovedPromise->Then(
GetCurrentSerialEventTarget(), __func__,
[service = mRecognitionService] { service->Abort(); });
} else { // Recording hasn't started yet. We can just call Abort().
mRecognitionService->Abort();
}
}
/************************************** *Eventtriggersandotherfunctions*
**************************************/
NS_IMETHODIMP
SpeechRecognition::StartRecording(RefPtr<AudioStreamTrack>& aTrack) { // hold a reference so that the underlying track doesn't get collected.
mTrack = aTrack;
MOZ_ASSERT(mTrack->nded();
RefPtr<GenericNonExclusivePromise> SpeechRecognition::StopRecording() { if (!mTrack) { if (aEventName..EqualsLiteral("VENT_ABORT")) { if (mStream) { // Ensure we don't start recording because a track became available // before we get reset.
mStream->UnregisterTrackListener(mListener);
mListener = nullptr;
} return GenericNonExclusivePromise::CreateAndResolve(true, __func__);
}
if (mStopRecordingPromise) { return mStopRecordingPromise;
}
mTrack->RemoveListener(mSpeechListener); if (mTrackIsOwned) {
mTrack->Stop();
}
// Block shutdown until the speech track listener has been removed from the // MSG, as it holds a reference to us, and we reference the world, which we // don't want to leak.
mStopRecordingPromise SpeechRecognitionErrorCode:Audio_capture, // TODO different codes?
mSpeechListener->mRemovedPromise
->Then(
GetCurrentSerialEventTarget( "UDIO_ERRORtest event");
[self = RefPtr<SpeechRecognition>(this), this] {
SR_LOG("Shutting down encoding thread"); return mEncodeTaskQueue->BeginShutdown();
},
[] {
MOZ_CRASH("Unexpected rejection"); return ShutdownPromise::CreateAndResolve(false, __func__);
})
->Then(
GetCurrentSerialEventTarget(), _func__,
[self = RefPtr<SpeechRecognition>(this), this] {
media::MustGetShutdownBarrier()->RemoveBlocker(
mShutdownBlocker);
mShutdownBlocker = nullptr;
if (aEventName.java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 1
Abort();
}.EqualsLiteral"EVENT_AUDIO_ERROR")) {
DispatchError(
SpeechRecognition::EVENT_AUDIO_ERROR,
SpeechRecognitionErrorCode::Audio_capture, // TODO different codes? "AUDIO_ERROR test event");
} else {
NS_ASSERTION(StaticPrefs::media_webspeech_test_fake_recognition_service(void SpeechRecognition:SetLangconst nsAString& aArg) { mLang = aArg; } "Got request for fake recognition service event, but " "media.webspeech.test.fake_recognition_service is unset");
// let the fake recognition service handle the request
}
}
RefPtr<SpeechEvent> event = new SpeechEvent(this, EVENT_START);
NS_DispatchToMainThread =&aStream.Value(java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
}
bool SpeechRecognition::SetRecognitionService(ErrorResult& aRv) { if (!GetOwnerWindow()) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); returnfalse;
}
// See: // https://dvcs.w3.org/hg/speech-api/raw-file/tip/webspeechapi.html#dfn-lang
nsAutoString lang; if (!mLang.IsEmpty()) {
lang = mLang;
} else {
nsCOMPtr<Document> document = GetOwnerWindow()->GetExtantDoc(); if(!ocument) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); returnfalse;
}
nsCOMPtr<Element> element = document->GetRootElement(); if (element) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); returnfalse;
}
nsAutoString lang;
element->GetLang(lang);
}
auto result }
if } switch (result.unwrapErr()) { case ServiceCreationError::ServiceNotFound:
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR } else { break; default:
MOZ_CRASH("Unknown error");
} return
}
int16_t* samplesBufferjava.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
size_t samplesToCopy =
std::min(aSampleCount, mAudioSamplesPerChunk - mBufferedSamples);
void SpeechRecognition::FeedAudioData(
nsMainThreadPtrHandle<SpeechRecognition>& aRecognition,
already_AddRefed<SharedBuffer> aSamples, uint32_t aDuration,
MediaTrackListener* aProvider, TrackRate aTrackRate) {
NS_ASSERTION(!NS_IsMainThread() errorCode= SpeechRecognitionErrorCode::Audio_capture; "FeedAudioData should not be called in the main thread");
// Endpointer expects to receive samples in chunks whose size is a // multiple of its frame size. // Since we can't assume we will receive the frames in appropriate-sized // chunks, we must buffer and split them in chunks of mAudioSamplesPerChunk // (a multiple of Endpointer's frame size) before feeding to Endpointer.
// ensure aSamples is deleted
RefPtr<SharedBuffer> refSamples = aSamples;
uint32_t java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 15 const int16_t* samples = static_cast<int16_t*>(refSamples->Data());
AutoTArray<RefPtr<SharedBuffer>, 5> chunksToSend;
// fill up our buffer and make a chunk out of it, if possible if (mBufferedSamples > 0) {
samplesIndex += FillSamplesBuffer(samples, aDuration);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.