eSpeak NG is an open source speech synthesizer that supports more than hundred languages and accents.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nativeTransferableStream.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. onload = async () => {
  2. chrome.runtime.sendNativeMessage(
  3. 'native_messaging_espeakng',
  4. {},
  5. async (nativeMessage) => {
  6. parent.postMessage(nativeMessage, name);
  7. await new Promise((resolve) => setTimeout(resolve, 100));
  8. const controller = new AbortController();
  9. const { signal } = controller;
  10. parent.postMessage('Ready.', name);
  11. onmessage = async (e) => {
  12. if (e.data instanceof ReadableStream) {
  13. try {
  14. const { value: file, done } = await e.data.getReader().read();
  15. const fd = new FormData();
  16. const stdin = await file.text();
  17. fd.append(file.name, stdin);
  18. const { body } = await fetch('http://localhost:8000', {
  19. method: 'post',
  20. cache: 'no-store',
  21. credentials: 'omit',
  22. body: fd,
  23. signal,
  24. });
  25. parent.postMessage(body, name, [body]);
  26. } catch (err) {
  27. parent.postMessage(err, name);
  28. }
  29. } else {
  30. if (e.data === 'Done writing input stream.') {
  31. chrome.runtime.sendNativeMessage(
  32. 'native_messaging_espeakng',
  33. {},
  34. (nativeMessage) => {
  35. parent.postMessage(nativeMessage, name);
  36. }
  37. );
  38. }
  39. if (e.data === 'Abort.') {
  40. controller.abort();
  41. }
  42. }
  43. };
  44. }
  45. );
  46. };