项目作者: guest271314

项目描述 :
espeak-ng using Native Messaging, Native File System, JavaScript
高级语言: JavaScript
项目地址: git://github.com/guest271314/native-messaging-espeak-ng.git
创建时间: 2020-01-06T01:09:11Z
项目社区:https://github.com/guest271314/native-messaging-espeak-ng

开源协议:

下载


Motivation

Web Speech API does not support SSML input to the speech synthesis engine https://github.com/WICG/speech-api/issues/10, or the ability to capture the output of speechSynthesis.speak() as aMedaiStreamTrack or raw audio https://lists.w3.org/Archives/Public/public-speech-api/2017Jun/0000.html.

See Issue 1115640: [FUGU] NativeTransferableStream.

Synopsis

"externally_connectable" => Native Messaging => eSpeak NG => MediaStreamTrack.

Use local espeak-ng with -m option set in the browser.

Output speech sythesis audio as a live MediaStreamTrack.

Use Native Messaging, Bash with GNU Core Utiltities to input text and Speech Synthesis Markup Language as STDIN to espeak-ng, stream STDOUT in “real-time” as live MediaStreamTrack.

Install


Dependencies


eSpeak NG Building eSpeak NG.


git clone https://github.com/guest271314/native-messaging-espeak-ng.git cd native-messaging-espeak-ng chmod u+x nm_espeak_ng.sh

Navigate to chrome://extensions, set Developer mode to on, click Load unpacked, select downloaded git directory.

Note the generated extension ID, substitute that value for <id> in nm_epseakng.json and AudioStream.js.

Substitute full local path to nm_espeakng.sh for /path/to in nm_espeakng.json.

"allowed_origins": [ "chrome-extension://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/" ]

Copy nm_espeakng.json to NativeMessagingHosts directory in Chromium or Chrome configuration folder, on Linux, i.e., ~/.config/chromium; ~/.config/google-chrome-unstable.

cp nm_espeakng.json ~/.config/chromium/NativeMessagingHosts

Reload extension.

Usage

On origins listed in "matches" array in "web_accessible_resources" and "externally_connectable" object in manifest.json, e.g., at console

  1. let text = `So we need people to have weird new
  2. ideas ... we need more ideas to break it
  3. and make it better ...
  4. Use it. Break it. File bugs. Request features.
  5. - Soledad Penadés, Real time front-end alchemy, or: capturing, playing,
  6. altering and encoding video and audio streams, without
  7. servers or plugins!
  8. <br>
  9. von Braun believed in testing. I cannot
  10. emphasize that term enough – test, test,
  11. test. Test to the point it breaks.
  12. - Ed Buckbee, NASA Public Affairs Officer, Chasing the Moon
  13. <br>
  14. Now watch. ..., this how science works.
  15. One researcher comes up with a result.
  16. And that is not the truth. No, no.
  17. A scientific emergent truth is not the
  18. result of one experiment. What has to
  19. happen is somebody else has to verify
  20. it. Preferably a competitor. Preferably
  21. someone who doesn't want you to be correct.
  22. - Neil deGrasse Tyson, May 3, 2017 at 92nd Street Y
  23. <br>
  24. It’s like they say, if the system fails you, you create your own system.
  25. - Michael K. Williams, Black Market
  26. <br>
  27. 1. If a (logical or axiomatic formal) system is consistent, it cannot be complete.
  28. 2. The consistency of axioms cannot be proved within their own system.
  29. - Kurt Gödel, Incompleteness Theorem, On Formally Undecidable Propositions of Principia Mathematica and Related Systems`;
  30. let {AudioStream} = await import(`chrome-extension://<id>/AudioStream.js?${new Date().getTime()}`)
  31. let audioStream = new AudioStream({stdin: `espeak-ng -m --stdout "${text}"`});
  32. await audioStream.start();

To record MediaStreamTrack pass recorder: true (set to false by default) to second parameter

  1. let audioStream = var audioStream = new AudioStream({
  2. stdin: `espeak-ng -m --stdout '<voice name="Storm">Hello world.<br></voice>'`,
  3. recorder: true
  4. });
  5. let ab = await audioStream.start(); // ArrayBuffer
  6. let blobURL = URL.createObjectURL(new Blob([ab], {type: 'audio/wav'}));

Abort the request and audio output.

  1. await audioStream.abort();
Dynamically set “externally_connectable” and “web_accessible_resources”

manifest.json is set by default to one match pattern, "https://*.github.com/*". To write the current active Tab URL match pattern in "matches" array of "externally_connectable" and "web_accessible_resources", click the extension icon, select native-messaging-espeak-ng extension directory, and grant permission to edit files in the folder using File System Access API.

References