Skip to content

Commit

Permalink
Merge pull request #17 from femshima/model-inside-container
Browse files Browse the repository at this point in the history
Model inside container
  • Loading branch information
cm-ayf authored Nov 24, 2023
2 parents 0c3fb43 + d3233db commit 933a0f2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 38 deletions.
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,21 @@ RUN npm ci
COPY ./src/ ./src/
RUN npm run build

FROM node:18 AS model-fetch

WORKDIR /app
RUN wget https://github.com/jpreprocess/jpreprocess/releases/download/v0.6.1/naist-jdic-jpreprocess.tar.gz \
&& tar xzf naist-jdic-jpreprocess.tar.gz \
&& rm naist-jdic-jpreprocess.tar.gz
RUN wget http://downloads.sourceforge.net/open-jtalk/hts_voice_nitech_jp_atr503_m001-1.05.tar.gz \
&& tar xzf hts_voice_nitech_jp_atr503_m001-1.05.tar.gz \
&& rm hts_voice_nitech_jp_atr503_m001-1.05.tar.gz

FROM gcr.io/distroless/nodejs18-debian12:nonroot AS runner
WORKDIR /app
ENV NODE_ENV=production
COPY ./package.json ./
COPY --from=builder /app/dist/ ./dist/
COPY --from=deps /app/node_modules/ ./node_modules/
COPY --from=model-fetch /app/ ./model/
CMD ["dist/main.js"]
61 changes: 28 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,34 @@ Discord.js Japan User Group向けの読み上げボットです.
`DISCORD_TOKEN=`の後に続けて,[Discord Developer Portal](https://discord.com/developers/applications)
から取得したトークンを記述してください.

次に,`model`ディレクトリを作成し,ダウンロードした辞書と音声モデルを置いてください.
辞書は
[naist-jdic-jpreprocess.tar.gz](https://github.com/jpreprocess/jpreprocess/releases/download/v0.6.1/naist-jdic-jpreprocess.tar.gz)
モデルは
[hts_voice_nitech_jp_atr503_m001-1.05.tar.gz](http://downloads.sourceforge.net/open-jtalk/hts_voice_nitech_jp_atr503_m001-1.05.tar.gz)
をお勧めします.
いずれもダウンロードした後解凍が必要です.

それぞれ次の図のように,パスが`model/naist-jdic``model/nitech_jp_atr503_m001.htsvoice`となるように配置してください.
```
(project-root)
┣ model
┃ ┣ naist-jdic
┃ ┃ ┣ char_def.bin
┃ ┃ ┣ dict.da
┃ ┃ ┣ dict.vals
┃ ┃ ┣ dict.words
┃ ┃ ┣ dict.wordsidx
┃ ┃ ┣ matrix.mtx
┃ ┃ ┗ unk.bin
┃ ┗ nitech_jp_atr503_m001.htsvoice
┗ .env
```

最後に,次のコマンドを実行すると,ボットが起動します(Dockerがインストールされていることが必要です).
次のコマンドを実行すると,ボットが起動します(Dockerがインストールされていることが必要です).

```bash
docker run \
--rm \
-d \
-v ./model:/app/model \
--env-file .env \
-e DICTIONARY=model/naist-jdic \
-e MODEL=model/nitech_jp_atr503_m001.htsvoice \
ghcr.io/discordjs-japan/om:latest
docker run --rm -d --env-file .env ghcr.io/discordjs-japan/om:latest
```

## Copyright Notice

For copyright of dependent packages, please see package.json.

### [HTS Voice "NIT ATR503 M001" version 1.05](http://downloads.sourceforge.net/open-jtalk/hts_voice_nitech_jp_atr503_m001-1.05.tar.gz)

> [!NOTE]
> HTS Voice is only included in Docker container
Creative Commons Attribution 3.0

- Copyright (c) 2003-2012 Nagoya Institute of Technology Department of Computer Science
- Copyright (c) 2003-2008 Tokyo Institute of Technology Interdisciplinary Graduate School of Science and Engineering

### [naist-jdic](https://github.com/jpreprocess/jpreprocess/releases/download/v0.6.1/naist-jdic-jpreprocess.tar.gz)

> [!NOTE]
> naist-jdic is only included in Docker container
BSD 3-Clause License

- Copyright (c) 2009, Nara Institute of Science and Technology, Japan.
- Copyright (c) 2011-2017, The UniDic Consortium
- Copyright (c) 2008-2016 Nagoya Institute of Technology Department of Computer Science
- Copyright (c) 2023, JPreprocess Team
8 changes: 3 additions & 5 deletions src/synthesis/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Synthesizer } from "./synthesizer";
import WorkerSynthesizer from "./worker-synthesizer";

if (!process.env.DICTIONARY || !process.env.MODEL) {
throw new Error("Dictionary and model must be specified.");
}
export const synthesizer: Synthesizer = new WorkerSynthesizer(
process.env.DICTIONARY,
process.env.MODEL,
process.env.DICTIONARY ?? "/app/model/naist-jdic",
process.env.MODEL ??
"/app/model/hts_voice_nitech_jp_atr503_m001-1.05/nitech_jp_atr503_m001.htsvoice",
);

0 comments on commit 933a0f2

Please sign in to comment.