-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Web Speech API in Javascript #8794
Comments
Hello! 👋 Thanks for logging this issue. Please remember we are all volunteers here, so some patience may be required before we can get to the issue. Also remember that the fastest way to get resolution on an issue is to propose a change directly, https://github.com/ankidroid/Anki-Android/wiki/Contributing |
Have you tried this one https://github.com/ankidroid/Anki-Android/wiki/FAQ#to-use-tts-on-ankidesktop-and-ankidroid SpeechSynthesisUtterance is not supported in android webview. So, above code will not work inside AnkiDroid reviewer. May be JAVA implementation will be done to create TTS. Also after rust conversion the TTS will be improved in latest release of AnkiDroid. |
In the current app specification, there is no way to achieve the behavior of speaking only the opened part of the text when cloze is opened. Is it possible to use Chrome Custum Tab instead of WebView to enable rich JavaScript? The availability of powerful JavaScript provides great extensibility to AnkiDroid, which has no add-ons. |
May be in AnkiDroid 2.15 or 2.16 the TTS will improved greatly even for cloze also.
I don't think so but you can submit PR.
The js addons support will be available for AnkiDroid soon. |
I've read the commentary and understood that the Web Speech API is difficult to use. This api provides a lot of custom freedom with TTS functionality. |
I tried to add TTS API for JS by a simple modification. SVID_20210510_152829.mp4<p><textarea id="textarea">This is TTS test.</textarea></p>
<p><button id="button1">Speak</button>
<script>
// CC0 http://creativecommons.org/publicdomain/zero/1.0/
var jsApi = {"version" : "0.0.1", "developer" : "[email protected]"};
var apiStatus = AnkiDroidJS.init(JSON.stringify(jsApi));
button1.addEventListener("click", () => {
const text = document.getElementById("textarea").value
AnkiDroidJS.speak_experimental(text);
});
</script> Calling TTS seems to work very well. |
You should create PR for this, you have already implemented it. But first wait for maintainers of AnkiDroid to give feedback on this features. I have also tried code like this. It works well. You may take some ideas from it. This function in @JavascriptInterface
public void ankiTextToSpeech(String text, String local) {
ankiJStts = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
@SuppressLint("NewApi")
@Override
public void onInit(int i) {
if (i == TextToSpeech.SUCCESS) {
int result = ankiJStts.setLanguage(new Locale(local));
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
Timber.i("Not supported or missing language data.");
} else {
ankiJStts.speak(text, TextToSpeech.QUEUE_ADD, null, "0000000");
}
}
}
}, "com.google.android.tts");
} Usage: <script>
AnkiDroidJS.ankiTextToSpeech("你好!,世界", "zh_CN");
</script> |
Also this is old message in discord for this features from @mikehardy. |
The video below is the cloze Speak on the user side that I first commented on. SVID_20210510_161354.mp4<script>
var jsApi = {"version" : "0.0.1", "developer" : "[email protected]"};
var apiStatus = AnkiDroidJS.init(JSON.stringify(jsApi));
var cloze = document.querySelector(".cloze");
AnkiDroidJS.speak_experimental(cloze.textContent);
</script> If the JavaScript TTS api is implemented, AnkiDroid will become even more powerful. |
Sure, propose a PR exposing TTS features via javascript, that's fine by me - just please make them generic so they are generally useful. I think that's a small hurdle though - I believe the only things we really do with TTS are start/stop the engine, start/stop speaking, add text to the speaking queue (?), and set a default TTS language for a deck (?) |
Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically |
@mikunimaru FYI: We're in the process of accepting Anki Desktop style TTS. Anki-Android/AnkiDroid/src/main/java/com/ichi2/libanki/Sound.kt Lines 27 to 37 in 253706a
I believe that this JS API is compatible with this class, but flagging it up in case we need to make changes before 2.16 goes out. |
As a solution to all the functional requirements related to TTS, I would like to propose support for the Web Speech API in JavaScript.
By supporting the Web Speech API, it will be possible to realize the speech behavior of the cloze-only tag, place the speech button in the card, and speak the text multiple times at different speeds using JavaScript on the user side.
This has the advantage of keeping the application side simple by leaving the implementation of overly complex functions related to TTS to the user's JavaScript side.
Below is the sample code.
I've also prepared a page where you can easily try out the code.
https://codepen.io/mikunimaru/pen/poevqKq
The above code is executable in my android browser, so I think android is capable of supporting Web Speech API.
The text was updated successfully, but these errors were encountered: