Nonebot2-based call to online fish-audio or offline fish-speech api text generation speech tts plugin

Chinese Simplified | English
Only a 5-second voice material can be used to perfectly clone the original sound! Just prepare the character voice you want to clone and label its voice filename (see below) to quickly generate voice.
Or use the official online api -> fish-audio to enjoy fast cloud voice generation.
Caution
This plug-in is for learning and research purposes only, and users must bear the risk of using the plug-in at their own risk. The author is not responsible for any losses or problems caused by the use of the plugin. Please use the plug-in reasonably and abide by relevant laws and regulations. By using this plug-in, you have read and agree to abide by the above disclaimer . If you do not agree or fail to comply with the above statement, please do not use this plug-in.
pipx installation
pipx install nonebot-plugin-fishspeech-tts -U[!note] Add this plugin in pyproject.toml of nonebot
nb-cli installation
nb plugin install nonebot-plugin-fishspeech-tts -U git clone installation (not recommended)
cmd git clone https://github.com/Cvandia/nonebot-plugin-fishspeech-ttsnonebot-plugin-fishspeech-tts at the window run to src/plugins in the root directory of the bot (or other name xxx/plugins when creating the bot)Recommended mirror site download
Tsinghua Source https://pypi.tuna.tsinghua.edu.cn/simple
Alibaba Source https://mirrors.aliyun.com/pypi/simple/
Add the following configuration in .env
| Basic configuration | type | Required | default value | illustrate |
|---|---|---|---|---|
| tts_is_online | bool | yes | True | Whether to use cloud API |
| tts_chunk_length | literal | no | "normal" | The audio shard length is normal when requested, optional: short, normal, long |
| tts_max_new_tokens | int | no | 800 | Maximum audio length, default is 800, setting to 0 is unlimited |
| tts_audio_path | str | no | "./data/reference audio" | Voice material path, default is "./data/reference audio" |
| tts_prefix | str | no | None | Trigger prefix, default to None |
Note: The file name format of the reference audio is: [Role Name] The text label corresponding to the audio. [Audio suffix name]
Click here to select to download the recommended reference audio reference_audio.zip , decompress and put the audio into data/参考音频in the bot file directory.
! Support different voices of the same character!
For details on audio suffix support, please refer to AUDIO_FILE_SUFFIX in files.py
If you want to use the official API, please set the configuration item tts_is_online to True and configure the following
| Configuration Items | type | Required | default value | illustrate |
|---|---|---|---|---|
| online_api_url | str | no | "https://api.fish-audio.cn" | The official website API address can be selected from https://api.fish.audio (walled) or default value |
| online_authorization | str | yes | "xxxxx" | Official API authentication key, please see the link for details |
| online_model_first | bool | no | True | If you want to call the official model, customize the character tone through your own reference audio, set this to False . Of course, if you do not prepare reference audio, you will also call the tone already available on the official website. For details, please refer to the link |
| online_api_proxy | str | no | None | Proxy address, such as: http://127.0.0.1:7890 |
If you want to use the API of your own or other fish-speech project, please set the configuration item tts_is_online to Fasle and configure the following
| Configuration Items | type | Required | default value | illustrate |
|---|---|---|---|---|
| offline_api_url offline_api_url | str | yes | "http://127.0.0.1:8080" | Your fish-speech api address |
Note
Please note your COMMAND_START and the above configuration items.
| instruction | need@ | scope | illustrate | Permissions |
|---|---|---|---|---|
| xxx says xxxx | According to configuration | all | tts voice generation | all |
| Voice list | yes | all | Get a list of all roles | all |
| Voice balance | yes | all | Query API balance | all |
Before use
Prepare fish-speech
fish-speech repository release code ( Source code (zip) ) to the localfish-speech root directoryinstall_env.bat to install the virtual environment and the required dependenciesstart.bat for the first timeAPI_FLAGS.txt and start it againStart API service
API_FLAGS.txt to roughly be the following content, that is, cancel # number in front of api # --infer
--api
--listen 0.0.0.0:8080 #监听接口
... Additional parameters that can be added in API_FLAGS.txt
--complie -> Whether to start the compiled model (faster generation of tts, but slower startup)--workers 数字>Start数字multi-coroutines (please be sure to set it, because the default one is easy to block)--device cpu -> Use cpu to generate tts (if using gpu, please ignore)--half -> Use half precision to generate tts--max-text-length -> Enter the maximum length of text