Add support for dictd and StarDict dictionaries

This commit is contained in:
John Factotum
2023-12-16 15:04:43 +08:00
parent ad5ec4d0e9
commit 1ff2d530c4
2 changed files with 271 additions and 0 deletions
+30
View File
@@ -284,6 +284,36 @@ The TTS module doesn't directly handle speech output. Rather, its methods return
The SSML attributes `ssml:ph` and `ssml:alphabet` are supported. There's no support for PLS and CSS Speech.
### Offline Dictionaries
The `dict.js` module can be used to load dictd and StarDict dictionaries. Usage:
```js
import { StarDict } from './dict.js'
import { inflate } from 'your inflate implementation'
const { ifo, dz, idx, syn } = { /* `File` (or `Blob`) objects */ }
const dict = new StarDict()
await dict.loadIfo(ifo)
await dict.loadDict(dz, inflate)
await dict.loadIdx(idx)
await dict.loadSyn(syn)
// look up words
const query = '...'
await dictionary.lookup(query)
await dictionary.synonyms(query)
```
Note that you must supply your own `inflate` function. Here is an example using [fflate](https://github.com/101arrowz/fflate):
```js
const inflate = data => new Promise(resolve => {
const inflate = new fflate.Inflate()
inflate.ondata = data => resolve(data)
inflate.push(data)
})
```
### OPDS
The `opds.js` module can be used to implement OPDS clients. It can convert OPDS 1.x documents to OPDS 2.0: