Automatic update from web-platform-tests Unprefix the Web Speech API This CL contains the following changes: - Unprefix the speech recognition part of the Web Speech API - Update the WebSpeechRecognitionContext feature status to experimental - Update WPTs with recent spec changes Intent to ship: https://groups.google.com/a/chromium.org/d/msgid/blink-dev/677c7f0e.2b0a0220.2e82a8.01f6.GAE%40google.com Fixed: 408029727 Change-Id: I261c5d1a855cb2028827a9e0a8282ef668506cf8 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6422562 Feels: Evan Liu <evliu@google.com> Commit-Queue: Evan Liu <evliu@google.com> Reviewed-by: Rick Byers <rbyers@chromium.org> Cr-Commit-Position: refs/heads/main@{#1471977} -- wpt-commits: 540c28e4684d7c78b39805d6085a4c848c282c9f wpt-pr: 53052
56 lines
2.0 KiB
HTML
56 lines
2.0 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<title>SpeechRecognition MediaStreamTrack</title>
|
|
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
|
|
<script>
|
|
async function getAudioTrackFromFile(filePath) {
|
|
const audioContext = new AudioContext();
|
|
const response = await fetch(filePath);
|
|
const arrayBuffer = await response.arrayBuffer();
|
|
const audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
|
|
const source = audioContext.createBufferSource();
|
|
source.buffer = audioBuffer;
|
|
|
|
const destination = audioContext.createMediaStreamDestination();
|
|
source.connect(destination);
|
|
source.start();
|
|
|
|
return destination.stream.getAudioTracks()[0];
|
|
}
|
|
|
|
promise_test(async (t) => {
|
|
const lang = "en-US";
|
|
window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
|
|
const speechRecognition = new SpeechRecognition();
|
|
speechRecognition.processLocally = false;
|
|
speechRecognition.lang = lang;
|
|
const audioTrack = await getAudioTrackFromFile("/media/speech.wav");
|
|
|
|
assert_true(audioTrack instanceof MediaStreamTrack, "Audio track should be a valid MediaStreamTrack");
|
|
|
|
const recognitionPromise = new Promise((resolve) => {
|
|
speechRecognition.onresult = (event) => {
|
|
const transcript = event.results[0][0].transcript;
|
|
resolve(transcript);
|
|
};
|
|
});
|
|
|
|
speechRecognition.start(audioTrack);
|
|
|
|
const transcript = await recognitionPromise;
|
|
assert_equals(transcript.toLowerCase(), "this is a sentence in a single segment", "Speech recognition should correctly recognize 'hello world'");
|
|
|
|
// Start speech recognition without a media stream track on the same instance should fail.
|
|
try {
|
|
speechRecognition.start();
|
|
assert_unreached();
|
|
} catch (e) {
|
|
assert_equals(e.name, "InvalidStateError", "Second call to start() should throw an InvalidStateError");
|
|
}
|
|
}, "SpeechRecognition should recognize speech from an audio file.");
|
|
</script>
|
|
</html>
|