SYSTEM NOTICE

Auto translation by AI. Be sure, accuracy, nuances and authorial intent may not be fully reflected.
見出し画像

Using the Linux version of VOICEVOX via shell only: Leveraging Linux's strength by eliminating the need for a GUI

Hello, this is Rcat.
This time, I will be using the Linux version of VOICEVOX, a free text-to-speech software, using only the shell.

When you download it from the official website, there is a Linux option, but after looking into it a bit, it seems like everyone is using it with a GUI. So, I downloaded it and
tried it out myself, and found that it can be used via the console alone, so I decided to summarize it in an article.

To give you a spoiler first, I will create a command like the one below.
Specify arguments in the shell to read aloud and save via redirection.Of course, SSH is fine.

$ ./voicevox -t ねこにゃんこきゃっと > test.wav


There are works that use VOICEVOX like the ones below.
If you are interested, please take a look.



Introduction

Terms of Service

Please check the terms of service in advance when using information or works.

https://note.com/rcat999/n/nb6a601a36ef5

About comments

Please check the guidelines in the terms of service before commenting.


Overview

Motivation

The motivation is that I am fully automating information analysis and summarization using generative AI, and I thought it would be interesting to add a feature to output that as an audio file that reads it aloud. All such systems run on Linux servers.

The article introduced at the top is set up to run on a Windows PC, so it was based on the premise of just downloading and launching the Windows version.
However, if you want to incorporate it into some kind of system, it must run on Linux.

After a quick search, I only found content about launching it using a GUI environment, so I ended up trying various things on my own.


How to download

Download the package

official websitePress the download button on the and select Linux.
At this time, by choosing the CPU-only version, a tar file will be added to that person's package, so we will use this.

The download starts when you press the download button, but I could not get the download link, so I decided to download it first and then transfer it to the server.
(It might also be possible to identify the link from the debug console and use wget.)

Official website https://voicevox.hiroshiba.jp/

Extracting

Enter the command as shown below to extract it.

$tar -zxvf  voicevox-linux-cpu-0.21.1.tar.gz
$ ls
VOICEVOX      voicevox-linux-cpu-0.21.1.tar.gz

Checking the data

The data has been extracted, so let's take a look at the contents.
At a glance, the file at the bottom without an extension looks like the executable file.

By the way, if you run this, it will look like the following.
I seem to recall seeing an explanation in the GUI version documentation about something called an X server GUI environment, so is it saying that it can't start in a GUI?
That means it's in the same state as when you download the Windows version as a ZIP and try to run it.

$ ./voicevox
Environment: production, appData: voicevox
configMigration014: /home/rcat/.config/voicevox-cpu/config.json not exists, do nothing
[348913:1110/220527.523549:ERROR:ozone_platform_x11.cc(244)] Missing X server or $DISPLAY
[348913:1110/220527.523590:ERROR:env.cc(258)] The platform failed to initialize.  Exiting.
Segmentation fault (コアダンプ)

Pulling myself together, I'll dig through the data a bit more.
Next, I'll go into the folder called engine.
Again, there is a file at the bottom without an extension. Moreover, the name suggests that I should execute this. Alright, let's execute it.

$ ./run
Warning: cpu_num_threads is set to 0. Setting it to half of the logical cores.
Info: Loading core 0.15.5.
reading /home/rcat/.local/share/voicevox-engine/user.dict_csv-94180179-fdad-4d3b-964f-70dc1a26b9eb.tmp ... 76
emitting double-array: 100% |###########################################|

done!
INFO:     Started server process [352241]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://localhost:50021 (Press CTRL+C to quit)

Whoa! It started. Just as I intended.It is now availablefor use.

Well, you might ask, how do I use it? In the following article, I perform voice synthesis using the VOICEVOX API.
It might be difficult because it involves programming, but I will use this method to perform text-to-speech from the console.

If you want to verify that it is actually running, the following is the quickest way.
You saw the URL written at the bottom of the console earlier, right? That is the API address.
Let's ask it to give us a list of characters. Just append "speakers" to the end of the URL.

$ curl http://localhost:50021/speakers
[{"name":"四国めたん","speaker_uuid":"7ffcb7ce-00ec-4bdc-82cd-45a8889e43ff","styles":[{"name":"ノーマル","id":2,"type":"talk"},{"name":"あまあま","id":0,"type":"talk"},{"name":"ツンツン","id":6,"type":"talk"},{"name":"セクシー","id":4,"type":"talk"},{"name":"ささやき","id":36,"type":"talk"},{"name":"ヒソヒソ","id":37,"type":"talk"}],"version":"0.15.5","supported_features":{"permitted_synthesis_morphing":"SELF_ONLY"}},{"name":"ずんだもん","speaker_uuid":"388f246b-8c41-4ac1-8e2d-5d79f3ff56d9","styles":[{"name":"ノーマル","id":3,"type":"talk"},{"name":"あまあま","id":1,"type":"talk"},{"name":"ツンツン","id":7,"type":"talk"},{"name":"セクシー","id":5,"type":"talk"},{"name":"ささやき","id":22,"type":"talk"},{"name":"ヒソヒソ","id":38,"type":"talk"},{"name":"ヘロヘロ","id":75,"type":"talk"},{"name":"なみだめ","id":76,"type":"talk"}],"version":"0.15.5","supported_features":{"permitted_synthesis_morphing":"SELF_ONLY"}},{"name":"春日部つむぎ","speaker_uuid":"35b2c544-660e-401e-b503-0e14c635303a","styles":[{"name":"ノーマル","id":8,"type":"talk"}],"version":"0.15.5","supported_features":{"permitted_synthesis_morphing":"ALL"}},...以下略

If a list of characters is returned like this, it is proof that it has started successfully.
The reason I won't try voice synthesis yet is that it requires two steps, and it's not at a level where I can just type it into the console manually.

By the way, the moment I accessed it, the access logs increased as shown below.


Easily reading aloud with a shell

Well, up to this point, we have been able to start the Linux version of VOICEVOX on the console.
After that, you can put it in the background or add it to systemd, and it will be fine even if you close the shell.

Now, for the main topic of voice reading.
Let's actually do it first, and then I'll move on to the explanation.

I will use the program created in the following article to generate a test voice.

Test to see if it can read aloud

Out of the data distributed above, I copied and brought only "voicevox.py".
By importing this module, you can perform reading aloud from Python.

The sample code is as follows.

$ python3
Python 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import voicevox
>>> v = voicevox.VOICEVOX()
>>> v.CreateWave("ねこはとってもかわいいです","test.wav")
{'path': 'test.wav', 'length': 1.6106666666666667, 'text': 'ねこはとってもかわいいです', 'diff': -1}
>>>
$ ls
VOICEVOX  __pycache__  test.wav  voicevox-linux-cpu-0.21.1.tar.gz  voicevox.py

The reading was completed in about 3 seconds. (CPU is N100)
The sample that was read aloud is as follows.

Voice: VOICEVOX "Kasukabe Tsumugi"
By the way, since Kasukabe Tsumugi is the one I use most often, if you omit the character, it will read aloud using Kasukabe Tsumugi.

By the way, the logs at this time are as follows.
You can see that it is accessing two APIs.

INFO:     127.0.0.1:55092 - "GET / HTTP/1.1" 200 OK
INFO:     127.0.0.1:37030 - "POST /audio_query?text=%E3%81%AD%E3%81%93%E3%81%AF%E3%81%A8%E3%81%A3%E3%81%A6%E3%82%82%E3%81%8B%E3%82%8F%E3%81%84%E3%81%84%E3%81%A7%E3%81%99&speaker=8 HTTP/1.1" 200 OK
INFO:     127.0.0.1:37038 - "POST /synthesis?speaker=8 HTTP/1.1" 200 OK

Read-aloud command

Now that we know we can read aloud from the shell, let's think about a way to use it easily.
First, I will introduce the final version right away.

$ ./voicevox -t ねこにゃんこきゃっと > test.wav
$ ls
VOICEVOX     test.wav                          voicevox.py  voicevoxtalk.log
__pycache__  voicevox-linux-cpu-0.21.1.tar.gz  voicevox  voicevoxtalk.py

If you play the "test.wav" created inside this, you can see that it is being read aloud.

Explanation of the read-aloud command

I created two new pieces of data to turn this into a command.

  • voicevoxtalk.py
    A script that performs the read-aloud done in the test earlier as a single operation.
    Optimized for command input.

  • voicevox
    A shell script to call voicevoxtalk.py.
    By using this, you no longer need to type the "python3" command yourself, making it feel like an original command.

The command to call is "voicevox".
You can perform a read-aloud by specifying the text you want to read, the character, and the speed.

You can check the help by specifying -h.
It feels a bit strange because my writing style header and the library usage instructions are mixed together.

$ ./voicevox -h
usage:
#==============================================================================#
#       VOICEVOX Linuxシェル読み上げ用コマンド                                   #
#==============================================================================#
(C) 2024 Rcat999
note: https://note.com/rcat999/
Twtter : @Rcat999
YouTube: Rcat999

+--------------概要--------------+
シェルからVOICEVOXを使うためのコマンド

+--------------利用規約--------------+
下記グローバルルールに則ります
https://note.com/rcat999/n/nb6a601a36ef5

+--------------履歴--------------+
Ver 1.0.0 2024/11/10 初版

options:
  -h, --help            show this help message and exit
  -t TEXT, --text TEXT  読み上げるテキストを指定
  -c CHARACTER, --character CHARACTER
                        読み上げるキャラクターIDを指定
  -s SPEED, --speed SPEED
                        読み上げ速度を指定

This script returns the generated audio to standard output. Therefore, please redirect it to save it or pass it to another command via a pipe.

By the way, for Zundamon at 0.5x speed, it is as follows.

$ ./voicevox -c 3 -s 0.5 -t ねこにゃんこきゃっと > zunda.wav

Contents of the command

The contents of voicevox are a shell script that calls Python.

Inside voicevox

The contents of the Python side are as follows.
It is what I entered in the console earlier, made easier to use as a command.


Next time

Next time, I have created a VOICEVOX intermediate API server that can be easily used from a custom system.
The official API is complex, but by using an intermediate server, you can easily read audio just by putting a string into the GET parameters, which can be utilized for various purposes.


Distribution information

Distribution URL

It is distributed from the following URL. Please agree to the
Terms of Service before using it.

https://script.google.com/macros/s/AKfycbxdcr8pnazR7RbjaSICTtaNWfN7h_rjQrKlZ3h9CZpPRFzRILk1OGc8mZqKbF-NXNO9/exec?name=VOICEVOX_Linuxシェルコマンド


いいなと思ったら応援しよう!

Rcat999 情報が役に立ったと思えば、僅かでも投げ銭していただけるとありがたいです。