├── .difyignore ├── .env.example ├── .gitattributes ├── .github └── workflows │ └── plugin-publish.yml ├── .gitignore ├── GUIDE.md ├── LICENSE ├── PRIVACY.md ├── README.md ├── _assets └── icon.svg ├── main.py ├── manifest.yaml ├── models └── tts │ ├── tts.py │ └── voicevox.yaml ├── provider ├── voicevox.py └── voicevox.yaml ├── requirements.txt └── resources ├── addfeature.png └── settings.png /.difyignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # Distribution / packaging 7 | .Python 8 | build/ 9 | develop-eggs/ 10 | dist/ 11 | downloads/ 12 | eggs/ 13 | .eggs/ 14 | lib/ 15 | lib64/ 16 | parts/ 17 | sdist/ 18 | var/ 19 | wheels/ 20 | share/python-wheels/ 21 | *.egg-info/ 22 | .installed.cfg 23 | *.egg 24 | MANIFEST 25 | 26 | # PyInstaller 27 | # Usually these files are written by a python script from a template 28 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 29 | *.manifest 30 | *.spec 31 | 32 | # Installer logs 33 | pip-log.txt 34 | pip-delete-this-directory.txt 35 | 36 | # Unit test / coverage reports 37 | htmlcov/ 38 | .tox/ 39 | .nox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *.cover 46 | *.py,cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | cover/ 50 | 51 | # Translations 52 | *.mo 53 | *.pot 54 | 55 | # Django stuff: 56 | *.log 57 | local_settings.py 58 | db.sqlite3 59 | db.sqlite3-journal 60 | 61 | # Flask stuff: 62 | instance/ 63 | .webassets-cache 64 | 65 | # Scrapy stuff: 66 | .scrapy 67 | 68 | # Sphinx documentation 69 | docs/_build/ 70 | 71 | # PyBuilder 72 | .pybuilder/ 73 | target/ 74 | 75 | # Jupyter Notebook 76 | .ipynb_checkpoints 77 | 78 | # IPython 79 | profile_default/ 80 | ipython_config.py 81 | 82 | # pyenv 83 | # For a library or package, you might want to ignore these files since the code is 84 | # intended to run in multiple environments; otherwise, check them in: 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | Pipfile.lock 93 | 94 | # UV 95 | # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. 96 | # This is especially recommended for binary packages to ensure reproducibility, and is more 97 | # commonly ignored for libraries. 98 | uv.lock 99 | 100 | # poetry 101 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 102 | # This is especially recommended for binary packages to ensure reproducibility, and is more 103 | # commonly ignored for libraries. 104 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 105 | poetry.lock 106 | 107 | # pdm 108 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 109 | #pdm.lock 110 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 111 | # in version control. 112 | # https://pdm.fming.dev/latest/usage/project/#working-with-version-control 113 | .pdm.toml 114 | .pdm-python 115 | .pdm-build/ 116 | 117 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 118 | __pypackages__/ 119 | 120 | # Celery stuff 121 | celerybeat-schedule 122 | celerybeat.pid 123 | 124 | # SageMath parsed files 125 | *.sage.py 126 | 127 | # Environments 128 | .env 129 | .venv 130 | env/ 131 | venv/ 132 | ENV/ 133 | env.bak/ 134 | venv.bak/ 135 | 136 | # Spyder project settings 137 | .spyderproject 138 | .spyproject 139 | 140 | # Rope project settings 141 | .ropeproject 142 | 143 | # mkdocs documentation 144 | /site 145 | 146 | # mypy 147 | .mypy_cache/ 148 | .dmypy.json 149 | dmypy.json 150 | 151 | # Pyre type checker 152 | .pyre/ 153 | 154 | # pytype static type analyzer 155 | .pytype/ 156 | 157 | # Cython debug symbols 158 | cython_debug/ 159 | 160 | # PyCharm 161 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 162 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 163 | # and can be added to the global gitignore or merged into this file. For a more nuclear 164 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 165 | .idea/ 166 | 167 | # Vscode 168 | .vscode/ 169 | 170 | # Git 171 | .git/ 172 | .gitignore 173 | .github/ 174 | 175 | # Mac 176 | .DS_Store 177 | 178 | # Windows 179 | Thumbs.db 180 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | INSTALL_METHOD=remote 2 | REMOTE_INSTALL_HOST=debug.dify.ai 3 | REMOTE_INSTALL_PORT=5003 4 | REMOTE_INSTALL_KEY=********-****-****-****-************ 5 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto -------------------------------------------------------------------------------- /.github/workflows/plugin-publish.yml: -------------------------------------------------------------------------------- 1 | name: Plugin Publish Workflow 2 | 3 | on: 4 | release: 5 | types: [published] 6 | 7 | jobs: 8 | publish: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Checkout code 12 | uses: actions/checkout@v3 13 | 14 | - name: Download CLI tool 15 | run: | 16 | mkdir -p $RUNNER_TEMP/bin 17 | cd $RUNNER_TEMP/bin 18 | 19 | wget https://github.com/langgenius/dify-plugin-daemon/releases/download/0.0.6/dify-plugin-linux-amd64 20 | chmod +x dify-plugin-linux-amd64 21 | 22 | echo "CLI tool location:" 23 | pwd 24 | ls -la dify-plugin-linux-amd64 25 | 26 | - name: Get basic info from manifest 27 | id: get_basic_info 28 | run: | 29 | PLUGIN_NAME=$(grep "^name:" manifest.yaml | cut -d' ' -f2) 30 | echo "Plugin name: $PLUGIN_NAME" 31 | echo "plugin_name=$PLUGIN_NAME" >> $GITHUB_OUTPUT 32 | 33 | VERSION=$(grep "^version:" manifest.yaml | cut -d' ' -f2) 34 | echo "Plugin version: $VERSION" 35 | echo "version=$VERSION" >> $GITHUB_OUTPUT 36 | 37 | # If the author's name is not your github username, you can change the author here 38 | AUTHOR=$(grep "^author:" manifest.yaml | cut -d' ' -f2) 39 | echo "Plugin author: $AUTHOR" 40 | echo "author=$AUTHOR" >> $GITHUB_OUTPUT 41 | 42 | - name: Package Plugin 43 | id: package 44 | run: | 45 | cd $GITHUB_WORKSPACE 46 | PACKAGE_NAME="${{ steps.get_basic_info.outputs.plugin_name }}-${{ steps.get_basic_info.outputs.version }}.difypkg" 47 | $RUNNER_TEMP/bin/dify-plugin-linux-amd64 plugin package . -o "$PACKAGE_NAME" 48 | 49 | echo "Package result:" 50 | ls -la "$PACKAGE_NAME" 51 | echo "package_name=$PACKAGE_NAME" >> $GITHUB_OUTPUT 52 | 53 | echo "\nFull file path:" 54 | pwd 55 | echo "\nDirectory structure:" 56 | tree || ls -R 57 | 58 | - name: Checkout target repo 59 | uses: actions/checkout@v3 60 | with: 61 | repository: ${{steps.get_basic_info.outputs.author}}/dify-plugins 62 | path: dify-plugins 63 | token: ${{ secrets.PLUGIN_ACTION }} 64 | fetch-depth: 1 65 | persist-credentials: true 66 | 67 | - name: Prepare and create PR 68 | run: | 69 | PACKAGE_NAME="${{ steps.get_basic_info.outputs.plugin_name }}-${{ steps.get_basic_info.outputs.version }}.difypkg" 70 | mkdir -p dify-plugins/${{ steps.get_basic_info.outputs.author }}/${{ steps.get_basic_info.outputs.plugin_name }} 71 | mv "$PACKAGE_NAME" dify-plugins/${{ steps.get_basic_info.outputs.author }}/${{ steps.get_basic_info.outputs.plugin_name }}/ 72 | 73 | cd dify-plugins 74 | 75 | git config user.name "GitHub Actions" 76 | git config user.email "actions@github.com" 77 | 78 | git fetch origin main 79 | git checkout main 80 | git pull origin main 81 | 82 | BRANCH_NAME="bump-${{ steps.get_basic_info.outputs.plugin_name }}-plugin-${{ steps.get_basic_info.outputs.version }}" 83 | git checkout -b "$BRANCH_NAME" 84 | 85 | git add . 86 | git commit -m "bump ${{ steps.get_basic_info.outputs.plugin_name }} plugin to version ${{ steps.get_basic_info.outputs.version }}" 87 | 88 | git push -u origin "$BRANCH_NAME" --force 89 | 90 | git branch -a 91 | echo "Waiting for branch to sync..." 92 | sleep 10 # Wait 10 seconds for branch sync 93 | 94 | - name: Create PR via GitHub API 95 | env: 96 | # How to config the token: 97 | # 1. Profile -> Settings -> Developer settings -> Personal access tokens -> Generate new token (with repo scope) -> Copy the token 98 | # 2. Go to the target repository -> Settings -> Secrets and variables -> Actions -> New repository secret -> Add the token as PLUGIN_ACTION 99 | GH_TOKEN: ${{ secrets.PLUGIN_ACTION }} 100 | run: | 101 | gh pr create \ 102 | --repo langgenius/dify-plugins \ 103 | --head "${{ steps.get_basic_info.outputs.author }}:${{ steps.get_basic_info.outputs.plugin_name }}-${{ steps.get_basic_info.outputs.version }}" \ 104 | --base main \ 105 | --title "bump ${{ steps.get_basic_info.outputs.plugin_name }} plugin to version ${{ steps.get_basic_info.outputs.version }}" \ 106 | --body "bump ${{ steps.get_basic_info.outputs.plugin_name }} plugin package to version ${{ steps.get_basic_info.outputs.version }} 107 | 108 | Changes: 109 | - Updated plugin package file" || echo "PR already exists or creation skipped." # Handle cases where PR already exists 110 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # UV 98 | # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | #uv.lock 102 | 103 | # poetry 104 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 105 | # This is especially recommended for binary packages to ensure reproducibility, and is more 106 | # commonly ignored for libraries. 107 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 108 | #poetry.lock 109 | 110 | # pdm 111 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 112 | #pdm.lock 113 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 114 | # in version control. 115 | # https://pdm.fming.dev/latest/usage/project/#working-with-version-control 116 | .pdm.toml 117 | .pdm-python 118 | .pdm-build/ 119 | 120 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 121 | __pypackages__/ 122 | 123 | # Celery stuff 124 | celerybeat-schedule 125 | celerybeat.pid 126 | 127 | # SageMath parsed files 128 | *.sage.py 129 | 130 | # Environments 131 | .env 132 | .venv 133 | env/ 134 | venv/ 135 | ENV/ 136 | env.bak/ 137 | venv.bak/ 138 | 139 | # Spyder project settings 140 | .spyderproject 141 | .spyproject 142 | 143 | # Rope project settings 144 | .ropeproject 145 | 146 | # mkdocs documentation 147 | /site 148 | 149 | # mypy 150 | .mypy_cache/ 151 | .dmypy.json 152 | dmypy.json 153 | 154 | # Pyre type checker 155 | .pyre/ 156 | 157 | # pytype static type analyzer 158 | .pytype/ 159 | 160 | # Cython debug symbols 161 | cython_debug/ 162 | 163 | # PyCharm 164 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 165 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 166 | # and can be added to the global gitignore or merged into this file. For a more nuclear 167 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 168 | .idea/ 169 | 170 | # Vscode 171 | .vscode/ 172 | 173 | # macOS 174 | .DS_Store 175 | .AppleDouble 176 | .LSOverride -------------------------------------------------------------------------------- /GUIDE.md: -------------------------------------------------------------------------------- 1 | ## User Guide of how to develop a Dify Plugin 2 | 3 | Hi there, looks like you have already created a Plugin, now let's get you started with the development! 4 | 5 | ### Choose a Plugin type you want to develop 6 | 7 | Before start, you need some basic knowledge about the Plugin types, Plugin supports to extend the following abilities in Dify: 8 | - **Tool**: Tool Providers like Google Search, Stable Diffusion, etc. it can be used to perform a specific task. 9 | - **Model**: Model Providers like OpenAI, Anthropic, etc. you can use their models to enhance the AI capabilities. 10 | - **Endpoint**: Like Service API in Dify and Ingress in Kubernetes, you can extend a http service as an endpoint and control its logics using your own code. 11 | 12 | Based on the ability you want to extend, we have divided the Plugin into three types: **Tool**, **Model**, and **Extension**. 13 | 14 | - **Tool**: It's a tool provider, but not only limited to tools, you can implement an endpoint there, for example, you need both `Sending Message` and `Receiving Message` if you are building a Discord Bot, **Tool** and **Endpoint** are both required. 15 | - **Model**: Just a model provider, extending others is not allowed. 16 | - **Extension**: Other times, you may only need a simple http service to extend the functionalities, **Extension** is the right choice for you. 17 | 18 | I believe you have chosen the right type for your Plugin while creating it, if not, you can change it later by modifying the `manifest.yaml` file. 19 | 20 | ### Manifest 21 | 22 | Now you can edit the `manifest.yaml` file to describe your Plugin, here is the basic structure of it: 23 | 24 | - version(version, required):Plugin's version 25 | - type(type, required):Plugin's type, currently only supports `plugin`, future support `bundle` 26 | - author(string, required):Author, it's the organization name in Marketplace and should also equals to the owner of the repository 27 | - label(label, required):Multi-language name 28 | - created_at(RFC3339, required):Creation time, Marketplace requires that the creation time must be less than the current time 29 | - icon(asset, required):Icon path 30 | - resource (object):Resources to be applied 31 | - memory (int64):Maximum memory usage, mainly related to resource application on SaaS for serverless, unit bytes 32 | - permission(object):Permission application 33 | - tool(object):Reverse call tool permission 34 | - enabled (bool) 35 | - model(object):Reverse call model permission 36 | - enabled(bool) 37 | - llm(bool) 38 | - text_embedding(bool) 39 | - rerank(bool) 40 | - tts(bool) 41 | - speech2text(bool) 42 | - moderation(bool) 43 | - node(object):Reverse call node permission 44 | - enabled(bool) 45 | - endpoint(object):Allow to register endpoint permission 46 | - enabled(bool) 47 | - app(object):Reverse call app permission 48 | - enabled(bool) 49 | - storage(object):Apply for persistent storage permission 50 | - enabled(bool) 51 | - size(int64):Maximum allowed persistent memory, unit bytes 52 | - plugins(object, required):Plugin extension specific ability yaml file list, absolute path in the plugin package, if you need to extend the model, you need to define a file like openai.yaml, and fill in the path here, and the file on the path must exist, otherwise the packaging will fail. 53 | - Format 54 | - tools(list[string]): Extended tool suppliers, as for the detailed format, please refer to [Tool Guide](https://docs.dify.ai/plugins/schema-definition/tool) 55 | - models(list[string]):Extended model suppliers, as for the detailed format, please refer to [Model Guide](https://docs.dify.ai/plugins/schema-definition/model) 56 | - endpoints(list[string]):Extended Endpoints suppliers, as for the detailed format, please refer to [Endpoint Guide](https://docs.dify.ai/plugins/schema-definition/endpoint) 57 | - Restrictions 58 | - Not allowed to extend both tools and models 59 | - Not allowed to have no extension 60 | - Not allowed to extend both models and endpoints 61 | - Currently only supports up to one supplier of each type of extension 62 | - meta(object) 63 | - version(version, required):manifest format version, initial version 0.0.1 64 | - arch(list[string], required):Supported architectures, currently only supports amd64 arm64 65 | - runner(object, required):Runtime configuration 66 | - language(string):Currently only supports python 67 | - version(string):Language version, currently only supports 3.12 68 | - entrypoint(string):Program entry, in python it should be main 69 | 70 | ### Install Dependencies 71 | 72 | - First of all, you need a Python 3.11+ environment, as our SDK requires that. 73 | - Then, install the dependencies: 74 | ```bash 75 | pip install -r requirements.txt 76 | ``` 77 | - If you want to add more dependencies, you can add them to the `requirements.txt` file, once you have set the runner to python in the `manifest.yaml` file, `requirements.txt` will be automatically generated and used for packaging and deployment. 78 | 79 | ### Implement the Plugin 80 | 81 | Now you can start to implement your Plugin, by following these examples, you can quickly understand how to implement your own Plugin: 82 | 83 | - [OpenAI](https://github.com/langgenius/dify-plugin-sdks/tree/main/python/examples/openai): best practice for model provider 84 | - [Google Search](https://github.com/langgenius/dify-plugin-sdks/tree/main/python/examples/google): a simple example for tool provider 85 | - [Neko](https://github.com/langgenius/dify-plugin-sdks/tree/main/python/examples/neko): a funny example for endpoint group 86 | 87 | ### Test and Debug the Plugin 88 | 89 | You may already noticed that a `.env.example` file in the root directory of your Plugin, just copy it to `.env` and fill in the corresponding values, there are some environment variables you need to set if you want to debug your Plugin locally. 90 | 91 | - `INSTALL_METHOD`: Set this to `remote`, your plugin will connect to a Dify instance through the network. 92 | - `REMOTE_INSTALL_HOST`: The host of your Dify instance, you can use our SaaS instance `https://debug.dify.ai`, or self-hosted Dify instance. 93 | - `REMOTE_INSTALL_PORT`: The port of your Dify instance, default is 5003 94 | - `REMOTE_INSTALL_KEY`: You should get your debugging key from the Dify instance you used, at the right top of the plugin management page, you can see a button with a `debug` icon, click it and you will get the key. 95 | 96 | Run the following command to start your Plugin: 97 | 98 | ```bash 99 | python -m main 100 | ``` 101 | 102 | Refresh the page of your Dify instance, you should be able to see your Plugin in the list now, but it will be marked as `debugging`, you can use it normally, but not recommended for production. 103 | 104 | ### Publish and Update the Plugin 105 | 106 | To streamline your plugin update workflow, you can configure GitHub Actions to automatically create PRs to the Dify plugin repository whenever you create a release. 107 | 108 | ##### Prerequisites 109 | 110 | - Your plugin source repository 111 | - A fork of the dify-plugins repository 112 | - Proper plugin directory structure in your fork 113 | 114 | #### Configure GitHub Action 115 | 116 | 1. Create a Personal Access Token with write permissions to your forked repository 117 | 2. Add it as a secret named `PLUGIN_ACTION` in your source repository settings 118 | 3. Create a workflow file at `.github/workflows/plugin-publish.yml` 119 | 120 | #### Usage 121 | 122 | 1. Update your code and the version in your `manifest.yaml` 123 | 2. Create a release in your source repository 124 | 3. The action automatically packages your plugin and creates a PR to your forked repository 125 | 126 | #### Benefits 127 | 128 | - Eliminates manual packaging and PR creation steps 129 | - Ensures consistency in your release process 130 | - Saves time during frequent updates 131 | 132 | --- 133 | 134 | For detailed setup instructions and example configuration, visit: [GitHub Actions Workflow Documentation](https://docs.dify.ai/plugins/publish-plugins/plugin-auto-publish-pr) 135 | 136 | ### Package the Plugin 137 | 138 | After all, just package your Plugin by running the following command: 139 | 140 | ```bash 141 | dify-plugin plugin package ./ROOT_DIRECTORY_OF_YOUR_PLUGIN 142 | ``` 143 | 144 | you will get a `plugin.difypkg` file, that's all, you can submit it to the Marketplace now, look forward to your Plugin being listed! 145 | 146 | 147 | ## User Privacy Policy 148 | 149 | Please fill in the privacy policy of the plugin if you want to make it published on the Marketplace, refer to [PRIVACY.md](PRIVACY.md) for more details. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 uezo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /PRIVACY.md: -------------------------------------------------------------------------------- 1 | ## Privacy 2 | 3 | !!! Please fill in the privacy policy of the plugin. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dify-voicevox-tts 2 | 3 | An experimental implementation of VOICEVOX text-to-speech custom model for Dify. 4 | 5 | ## 📦 Installation 6 | 7 | - Download this repo. 8 | - Copy the voicevox directory to `api/core/model_runtime/model_providers` in the API server. 9 | - Restart the API server. 10 | 11 | If you are not able to build the API server container image yourself, you can copy the directory to the container and save it with the following steps: 12 | 13 | ```sh 14 | docker cp /path/to/voicevox :/app/api/core/model_runtime/model_providers 15 | docker commit 16 | ``` 17 | 18 | 19 | ## ✨ Add model 20 | 21 | Set up VOICEVOX in the list of model providers. The URL must be reachable from the inside of the API container. `http://127.0.0.1:50021` doesn't work without any network configurations. 22 | 23 | ![Add model](resources/settings.png) 24 | 25 | 26 | ## 🥳 Use TTS feature 27 | 28 | Click [Features] > [+ Add Feature] and turn on `Text to Speech`. 29 | 30 | ![Add feature](resources/addfeature.png) 31 | 32 | Enjoy👍 33 | 34 | 35 | ## 🙏 I NEED YOUR CONTRIBUTION 36 | 37 | This is just an experimental implementation, and we need your help to make it better. Please contribute! 🚀✨ 38 | -------------------------------------------------------------------------------- /_assets/icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 6 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from dify_plugin import Plugin, DifyPluginEnv 2 | 3 | plugin = Plugin(DifyPluginEnv(MAX_REQUEST_TIMEOUT=120)) 4 | 5 | if __name__ == '__main__': 6 | plugin.run() 7 | -------------------------------------------------------------------------------- /manifest.yaml: -------------------------------------------------------------------------------- 1 | version: 0.0.1 2 | type: plugin 3 | author: uezo 4 | name: voicevox 5 | label: 6 | en_US: voicevox 7 | ja_JP: voicevox 8 | zh_Hans: voicevox 9 | pt_BR: voicevox 10 | description: 11 | en_US: VOICEVOX text-to-speech custom model for Dify 12 | ja_JP: VOICEVOX text-to-speech custom model for Dify 13 | zh_Hans: VOICEVOX text-to-speech custom model for Dify 14 | pt_BR: VOICEVOX text-to-speech custom model for Dify 15 | icon: icon.svg 16 | resource: 17 | memory: 268435456 18 | permission: 19 | model: 20 | enabled: true 21 | llm: false 22 | text_embedding: false 23 | rerank: false 24 | tts: true 25 | speech2text: false 26 | moderation: false 27 | plugins: 28 | models: 29 | - provider/voicevox.yaml 30 | meta: 31 | version: 0.0.1 32 | arch: 33 | - amd64 34 | - arm64 35 | runner: 36 | language: python 37 | version: "3.12" 38 | entrypoint: main 39 | minimum_dify_version: null 40 | created_at: 2025-04-25T23:19:15.84143822+09:00 41 | privacy: PRIVACY.md 42 | verified: false 43 | -------------------------------------------------------------------------------- /models/tts/tts.py: -------------------------------------------------------------------------------- 1 | from collections.abc import Generator 2 | from typing import Optional 3 | 4 | import concurrent.futures 5 | from io import BytesIO 6 | from typing import Optional 7 | from pydub import AudioSegment 8 | import httpx 9 | 10 | from dify_plugin import TTSModel 11 | from dify_plugin.errors.model import ( 12 | CredentialsValidateFailedError, 13 | InvokeBadRequestError, 14 | InvokeError, 15 | InvokeServerUnavailableError 16 | ) 17 | 18 | 19 | class VoicevoxText2SpeechModel(TTSModel): 20 | """ 21 | Model class for OpenAI Speech to text model. 22 | """ 23 | 24 | def _invoke( 25 | self, 26 | model: str, 27 | tenant_id, 28 | credentials: dict, 29 | content_text: str, 30 | voice: str, 31 | user: Optional[str] = None, 32 | ) -> bytes | Generator[bytes, None, None]: 33 | """ 34 | _invoke text2speech model 35 | 36 | :param model: model name 37 | :param tenant_id: user tenant id 38 | :param credentials: model credentials 39 | :param content_text: text content to be translated 40 | :param voice: model timbre 41 | :param user: unique user id 42 | :return: text translated to audio file 43 | """ 44 | if not voice or voice not in [d["value"] for d in self.get_tts_model_voices(model=model, credentials=credentials)]: 45 | voice = self._get_model_default_voice(model, credentials) 46 | return self._tts_invoke(model=model, credentials=credentials, content_text=content_text, voice=voice) 47 | 48 | def validate_credentials( 49 | self, model: str, credentials: dict, user: Optional[str] = None 50 | ) -> None: 51 | """ 52 | validate credentials text2speech model 53 | 54 | :param model: model name 55 | :param credentials: model credentials 56 | :param user: unique user id 57 | :return: text translated to audio file 58 | """ 59 | try: 60 | next(self._tts_invoke( 61 | model=model, 62 | credentials=credentials, 63 | content_text="こんにちは。", 64 | voice=self._get_model_default_voice(model, credentials), 65 | )) 66 | except Exception as ex: 67 | raise CredentialsValidateFailedError(str(ex)) 68 | 69 | def _tts_invoke(self, model: str, credentials: dict, content_text: str, voice: str) -> any: 70 | audio_type = self._get_model_audio_type(model, credentials) 71 | word_limit = self._get_model_word_limit(model, credentials) 72 | max_workers = self._get_model_workers_limit(model, credentials) 73 | try: 74 | sentences = list(self._split_text_into_sentences(org_text=content_text, max_length=word_limit)) 75 | # Create a thread pool and map the function to the list of sentences 76 | with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor: 77 | futures = [executor.submit(self._process_sentence, sentence=sentence, voice=voice, 78 | api_base=credentials["voicevox_api_base"]) for sentence in sentences] 79 | for future in futures: 80 | if future.result(): 81 | buffer: BytesIO = BytesIO() 82 | segment = AudioSegment.from_file(BytesIO(future.result()), format=audio_type) 83 | segment.export(buffer, format="mp3") 84 | buffer.seek(0) 85 | yield buffer.read() 86 | except Exception as ex: 87 | raise InvokeBadRequestError(str(ex)) 88 | 89 | def _process_sentence(self, sentence: str, voice: str, api_base: str): 90 | with httpx.Client() as client: 91 | query_resp = client.post(api_base + "/audio_query", params={"speaker": voice, "text": sentence.strip()},timeout=30.0) 92 | audio_query = query_resp.json() 93 | audio_resp = client.post(api_base + "/synthesis", params={"speaker": voice}, json=audio_query, timeout=30.0) 94 | if isinstance(audio_resp.content, bytes): 95 | return audio_resp.content 96 | 97 | @property 98 | def _invoke_error_mapping(self) -> dict[type[InvokeError], list[type[Exception]]]: 99 | # TODO: Break down the errors 100 | return { 101 | InvokeServerUnavailableError: [Exception], 102 | } -------------------------------------------------------------------------------- /models/tts/voicevox.yaml: -------------------------------------------------------------------------------- 1 | model: voicevox 2 | model_type: tts 3 | model_properties: 4 | default_voice: '2' 5 | voices: 6 | - mode: '2' 7 | name: '四国めたん - ノーマル' 8 | language: ['ja-JP'] 9 | - mode: '0' 10 | name: '四国めたん - あまあま' 11 | language: ['ja-JP'] 12 | - mode: '6' 13 | name: '四国めたん - ツンツン' 14 | language: ['ja-JP'] 15 | - mode: '4' 16 | name: '四国めたん - セクシー' 17 | language: ['ja-JP'] 18 | - mode: '36' 19 | name: '四国めたん - ささやき' 20 | language: ['ja-JP'] 21 | - mode: '37' 22 | name: '四国めたん - ヒソヒソ' 23 | language: ['ja-JP'] 24 | - mode: '3' 25 | name: 'ずんだもん - ノーマル' 26 | language: ['ja-JP'] 27 | - mode: '1' 28 | name: 'ずんだもん - あまあま' 29 | language: ['ja-JP'] 30 | - mode: '7' 31 | name: 'ずんだもん - ツンツン' 32 | language: ['ja-JP'] 33 | - mode: '5' 34 | name: 'ずんだもん - セクシー' 35 | language: ['ja-JP'] 36 | - mode: '22' 37 | name: 'ずんだもん - ささやき' 38 | language: ['ja-JP'] 39 | - mode: '38' 40 | name: 'ずんだもん - ヒソヒソ' 41 | language: ['ja-JP'] 42 | - mode: '75' 43 | name: 'ずんだもん - ヘロヘロ' 44 | language: ['ja-JP'] 45 | - mode: '76' 46 | name: 'ずんだもん - なみだめ' 47 | language: ['ja-JP'] 48 | - mode: '8' 49 | name: '春日部つむぎ - ノーマル' 50 | language: ['ja-JP'] 51 | - mode: '10' 52 | name: '雨晴はう - ノーマル' 53 | language: ['ja-JP'] 54 | - mode: '9' 55 | name: '波音リツ - ノーマル' 56 | language: ['ja-JP'] 57 | - mode: '65' 58 | name: '波音リツ - クイーン' 59 | language: ['ja-JP'] 60 | - mode: '11' 61 | name: '玄野武宏 - ノーマル' 62 | language: ['ja-JP'] 63 | - mode: '39' 64 | name: '玄野武宏 - 喜び' 65 | language: ['ja-JP'] 66 | - mode: '40' 67 | name: '玄野武宏 - ツンギレ' 68 | language: ['ja-JP'] 69 | - mode: '41' 70 | name: '玄野武宏 - 悲しみ' 71 | language: ['ja-JP'] 72 | - mode: '12' 73 | name: '白上虎太郎 - ふつう' 74 | language: ['ja-JP'] 75 | - mode: '32' 76 | name: '白上虎太郎 - わーい' 77 | language: ['ja-JP'] 78 | - mode: '33' 79 | name: '白上虎太郎 - びくびく' 80 | language: ['ja-JP'] 81 | - mode: '34' 82 | name: '白上虎太郎 - おこ' 83 | language: ['ja-JP'] 84 | - mode: '35' 85 | name: '白上虎太郎 - びえーん' 86 | language: ['ja-JP'] 87 | - mode: '13' 88 | name: '青山龍星 - ノーマル' 89 | language: ['ja-JP'] 90 | - mode: '81' 91 | name: '青山龍星 - 熱血' 92 | language: ['ja-JP'] 93 | - mode: '82' 94 | name: '青山龍星 - 不機嫌' 95 | language: ['ja-JP'] 96 | - mode: '83' 97 | name: '青山龍星 - 喜び' 98 | language: ['ja-JP'] 99 | - mode: '84' 100 | name: '青山龍星 - しっとり' 101 | language: ['ja-JP'] 102 | - mode: '85' 103 | name: '青山龍星 - かなしみ' 104 | language: ['ja-JP'] 105 | - mode: '86' 106 | name: '青山龍星 - 囁き' 107 | language: ['ja-JP'] 108 | - mode: '14' 109 | name: '冥鳴ひまり - ノーマル' 110 | language: ['ja-JP'] 111 | - mode: '16' 112 | name: '九州そら - ノーマル' 113 | language: ['ja-JP'] 114 | - mode: '15' 115 | name: '九州そら - あまあま' 116 | language: ['ja-JP'] 117 | - mode: '18' 118 | name: '九州そら - ツンツン' 119 | language: ['ja-JP'] 120 | - mode: '17' 121 | name: '九州そら - セクシー' 122 | language: ['ja-JP'] 123 | - mode: '19' 124 | name: '九州そら - ささやき' 125 | language: ['ja-JP'] 126 | - mode: '20' 127 | name: 'もち子さん - ノーマル' 128 | language: ['ja-JP'] 129 | - mode: '66' 130 | name: 'もち子さん - セクシー/あん子' 131 | language: ['ja-JP'] 132 | - mode: '77' 133 | name: 'もち子さん - 泣き' 134 | language: ['ja-JP'] 135 | - mode: '78' 136 | name: 'もち子さん - 怒り' 137 | language: ['ja-JP'] 138 | - mode: '79' 139 | name: 'もち子さん - 喜び' 140 | language: ['ja-JP'] 141 | - mode: '80' 142 | name: 'もち子さん - のんびり' 143 | language: ['ja-JP'] 144 | - mode: '21' 145 | name: '剣崎雌雄 - ノーマル' 146 | language: ['ja-JP'] 147 | - mode: '23' 148 | name: 'WhiteCUL - ノーマル' 149 | language: ['ja-JP'] 150 | - mode: '24' 151 | name: 'WhiteCUL - たのしい' 152 | language: ['ja-JP'] 153 | - mode: '25' 154 | name: 'WhiteCUL - かなしい' 155 | language: ['ja-JP'] 156 | - mode: '26' 157 | name: 'WhiteCUL - びえーん' 158 | language: ['ja-JP'] 159 | - mode: '27' 160 | name: '後鬼 - 人間ver.' 161 | language: ['ja-JP'] 162 | - mode: '28' 163 | name: '後鬼 - ぬいぐるみver.' 164 | language: ['ja-JP'] 165 | - mode: '29' 166 | name: 'No.7 - ノーマル' 167 | language: ['ja-JP'] 168 | - mode: '30' 169 | name: 'No.7 - アナウンス' 170 | language: ['ja-JP'] 171 | - mode: '31' 172 | name: 'No.7 - 読み聞かせ' 173 | language: ['ja-JP'] 174 | - mode: '42' 175 | name: 'ちび式じい - ノーマル' 176 | language: ['ja-JP'] 177 | - mode: '43' 178 | name: '櫻歌ミコ - ノーマル' 179 | language: ['ja-JP'] 180 | - mode: '44' 181 | name: '櫻歌ミコ - 第二形態' 182 | language: ['ja-JP'] 183 | - mode: '45' 184 | name: '櫻歌ミコ - ロリ' 185 | language: ['ja-JP'] 186 | - mode: '46' 187 | name: '小夜/SAYO - ノーマル' 188 | language: ['ja-JP'] 189 | - mode: '47' 190 | name: 'ナースロボ_タイプT - ノーマル' 191 | language: ['ja-JP'] 192 | - mode: '48' 193 | name: 'ナースロボ_タイプT - 楽々' 194 | language: ['ja-JP'] 195 | - mode: '49' 196 | name: 'ナースロボ_タイプT - 恐怖' 197 | language: ['ja-JP'] 198 | - mode: '50' 199 | name: 'ナースロボ_タイプT - 内緒話' 200 | language: ['ja-JP'] 201 | - mode: '51' 202 | name: '†聖騎士 紅桜† - ノーマル' 203 | language: ['ja-JP'] 204 | - mode: '52' 205 | name: '雀松朱司 - ノーマル' 206 | language: ['ja-JP'] 207 | - mode: '53' 208 | name: '麒ヶ島宗麟 - ノーマル' 209 | language: ['ja-JP'] 210 | - mode: '54' 211 | name: '春歌ナナ - ノーマル' 212 | language: ['ja-JP'] 213 | - mode: '55' 214 | name: '猫使アル - ノーマル' 215 | language: ['ja-JP'] 216 | - mode: '56' 217 | name: '猫使アル - おちつき' 218 | language: ['ja-JP'] 219 | - mode: '57' 220 | name: '猫使アル - うきうき' 221 | language: ['ja-JP'] 222 | - mode: '58' 223 | name: '猫使ビィ - ノーマル' 224 | language: ['ja-JP'] 225 | - mode: '59' 226 | name: '猫使ビィ - おちつき' 227 | language: ['ja-JP'] 228 | - mode: '60' 229 | name: '猫使ビィ - 人見知り' 230 | language: ['ja-JP'] 231 | - mode: '61' 232 | name: '中国うさぎ - ノーマル' 233 | language: ['ja-JP'] 234 | - mode: '62' 235 | name: '中国うさぎ - おどろき' 236 | language: ['ja-JP'] 237 | - mode: '63' 238 | name: '中国うさぎ - こわがり' 239 | language: ['ja-JP'] 240 | - mode: '64' 241 | name: '中国うさぎ - へろへろ' 242 | language: ['ja-JP'] 243 | - mode: '67' 244 | name: '栗田まろん - ノーマル' 245 | language: ['ja-JP'] 246 | - mode: '68' 247 | name: 'あいえるたん - ノーマル' 248 | language: ['ja-JP'] 249 | - mode: '69' 250 | name: '満別花丸 - ノーマル' 251 | language: ['ja-JP'] 252 | - mode: '70' 253 | name: '満別花丸 - 元気' 254 | language: ['ja-JP'] 255 | - mode: '71' 256 | name: '満別花丸 - ささやき' 257 | language: ['ja-JP'] 258 | - mode: '72' 259 | name: '満別花丸 - ぶりっ子' 260 | language: ['ja-JP'] 261 | - mode: '73' 262 | name: '満別花丸 - ボーイ' 263 | language: ['ja-JP'] 264 | - mode: '74' 265 | name: '琴詠ニア - ノーマル' 266 | language: ['ja-JP'] 267 | word_limit: 40 268 | audio_type: 'wav' 269 | max_workers: 5 270 | pricing: 271 | input: '0.0' 272 | output: '0' 273 | unit: '0.0' 274 | currency: USD -------------------------------------------------------------------------------- /provider/voicevox.py: -------------------------------------------------------------------------------- 1 | import logging 2 | from collections.abc import Mapping 3 | 4 | from dify_plugin import ModelProvider 5 | from dify_plugin.entities.model import ModelType 6 | from dify_plugin.errors.model import CredentialsValidateFailedError 7 | 8 | logger = logging.getLogger(__name__) 9 | 10 | 11 | class VoicevoxModelProvider(ModelProvider): 12 | def validate_provider_credentials(self, credentials: Mapping) -> None: 13 | """ 14 | Validate provider credentials 15 | if validate failed, raise exception 16 | 17 | :param credentials: provider credentials, credentials form defined in `provider_credential_schema`. 18 | """ 19 | try: 20 | model_instance = self.get_model_instance(ModelType.TTS) 21 | model_instance.validate_credentials( 22 | model='voicevox', 23 | credentials=credentials 24 | ) 25 | except CredentialsValidateFailedError as ex: 26 | raise ex 27 | except Exception as ex: 28 | logger.exception( 29 | f"{self.get_provider_schema().provider} credentials validate failed" 30 | ) 31 | raise ex 32 | -------------------------------------------------------------------------------- /provider/voicevox.yaml: -------------------------------------------------------------------------------- 1 | provider: voicevox 2 | label: 3 | en_US: VOICEVOX 4 | description: 5 | en_US: VOICEVOX 6 | background: "#a5d4ad" 7 | help: 8 | title: 9 | en_US: VOICEVOX Official Website 10 | url: 11 | en_US: https://voicevox.hiroshiba.jp 12 | supported_model_types: 13 | - tts 14 | configurate_methods: 15 | - predefined-model 16 | provider_credential_schema: 17 | credential_form_schemas: 18 | - variable: voicevox_api_base 19 | label: 20 | en_US: API Base 21 | type: text-input 22 | required: true 23 | placeholder: 24 | en_US: Enter VOICEVOX API Base, e.g. https://your.voicevox.server:50021 25 | models: 26 | tts: 27 | predefined: 28 | - "models/tts/*.yaml" 29 | extra: 30 | python: 31 | provider_source: provider/voicevox.py 32 | model_sources: 33 | - "models/tts/tts.py" 34 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | dify_plugin>=0.1.0,<0.2.0 2 | -------------------------------------------------------------------------------- /resources/addfeature.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uezo/dify-voicevox-tts/c452629facb940a2cf233420b329cb9bb4a75899/resources/addfeature.png -------------------------------------------------------------------------------- /resources/settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uezo/dify-voicevox-tts/c452629facb940a2cf233420b329cb9bb4a75899/resources/settings.png --------------------------------------------------------------------------------