
voicevoxを使ってみます。無料で使える中品質なテキスト読み上げソフトウェア、VOICEVOXのエディター
voicevox-engineというapiが公開されているのでhttpリクエストを送るだけでかんたんに音声合成が可能です。version: "2"
services:
voicevox_engine:
# CPUの場合は voicevox/voicevox_engine:cpu-ubuntu20.04-latest を使用
image: voicevox/voicevox_engine:nvidia-ubuntu20.04-latest
ports:
- "50021:50021"
tty: true
#
# 以下の項目はCPUの場合はなくても大丈夫
#
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]docker-compose.ymlを保存したら実行。docker-compose upnpm i voicevox-api-client --save
# yarn add voicevox-api-client,
# npm add voicevox-api-client, etc...// index.mjs
import { Client } from 'voicevox-api-client'
import fs from 'fs'
const client = new Client('http://localhost:50021')
const createVoice = async (text: string) => {
const query = await client.query.createQuery(0, text)
const voice = await client.voice.createVoice(0, query)
const buf = Buffer.from(voice)
fs.writeFileSync('voice.wav', buf)
}
createVoice("Dockerがどっかーん")Clientをインポートしてインスタンスを作成しています。voicevox-engineのサーバーのURLにしてください。// index.mjs
import { Client } from 'voicevox-api-client'
import fs from 'fs'
const client = new Client('http://localhost:50021')createVoice関数。voiceに音声のarrayBufferが入るのでBufferに変換してファイルに書き出します。// index.mjs
const createVoice = async (text: string) => {
const query = await client.query.createQuery(0, text)
const voice = await client.voice.createVoice(0, query)
const buf = Buffer.from(voice)
fs.writeFileSync('voice.wav', buf)
}node index.mjs