HugoFara / lwt

Learn languages by reading! A language learning app stemmed from Learning with Texts (LWT).
https://hugofara.github.io/lwt/
The Unlicense
164 stars 19 forks source link

[Feature] Add Voice API support #153

Closed ProgramComputer closed 7 months ago

ProgramComputer commented 9 months ago

As implied in #143, there are multiple TTS services that LWT can add functionality for especially the common ones; however, the varied authentication required for most can lead to bloat not to mention your desired TTS service not being present.

With this pull request, a generality of TTS-calls is used for customizability on the user-end whether Azure, Google Cloud, ... * as long as the response contains a data: URI.

A key note is that prior authorization is up to the user to configure. The user will have to provide it in the fetch JSON.

Input is the resource itself to fetch including any URL params. Options are the modifiers supplied to the call.

A placeholder of 'lwt_text' is required in the below object. lwt_lang is an optional placeholder for the lang code.

Leave the textarea empty to disable otherwise default browser SpeechAPI won't run. The format is below.

{
"input":
,
"options":
}

steps to test

In text-to-speech settings add the request in JSON format to the Voice API Request text area and save.

Then in read mode, click the audio buttons.

limitations

next steps

Currently 'lwt_text' and 'lwt_lang' placeholders are revealed for user customizability but pitch and rate could also be given.

example request

As using subscriber services from Amazon Polly or Google text-to-speech would require authentication, huggingface is used for the example. The following can be pasted for the Japanese language text-to-speech configuration.

{
  "input": "https://skytnt-moe-tts.hf.space/run/predict",
  "options": {
    "method": "POST",
    "body": {
      "data": [
        "lwt_text",
        "鎌倉詩桜",
        1,
        false
      ],
      "event_data": "undefined",
      "fn_index": "5"
    },
    "headers": {
      "Content-Type": "application/json"
    }
  }
}

user contribs

If you would like, reply to the thread with the parameters you used in a successful JSON request call for whichever particular resource such as Azure, Polly, or Google text-to-speech as some resources are authentication tedious.

HugoFara commented 7 months ago

Phew, I finally managed to merge it :hot_face:

Instead of saving it as a cookie, it will be saved in the database as a language entity. The automatic database update will come a bit later but you can change it manually running ALTER TABLE languages ADD COLUMN LgTTSVoiceAPI varchar(2048) NOT NULL.

I also created a discussion on #174 so that users can share their tips. Inside LWT, the documentation is minimal for now, I may expend it later (I plan on scavenging data from #174).

It's a nice feature, great job on this!