Created
May 10, 2026 05:54
-
-
Save MasWag/2f059693e6dafc07c7bf342adaf20623 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;;; voicevox --- Voicevox utility for Emacs. | |
| ;; Copyright (C) 2024 TakesxiSximada | |
| ;; Author: TakesxiSximada | |
| ;; Maintainer: TakesxiSximada | |
| ;; Version: 1.0 | |
| ;; Package-Version: 20230116.0000 | |
| ;; Package-Requires: ((emacs "29.1")) | |
| ;; Date: 2023-01-16 | |
| ;; This file is not part of GNU Emacs. | |
| ;;; License: | |
| ;; This program is free software: you can redistribute it and/or | |
| ;; modify it under the terms of the GNU Affero General Public License as | |
| ;; published by the Free Software Foundation, either version 3 of the | |
| ;; License, or (at your option) any later version. | |
| ;; This program is distributed in the hope that it will be useful, | |
| ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| ;; Affero General Public License for more details. | |
| ;; You should have received a copy of the GNU Affero General Public | |
| ;; License along with this program. If not, see | |
| ;; <https://www.gnu.org/licenses/>. | |
| ;;; Commentary: | |
| ;; Voicevox Emacs Integration. | |
| ;;; Code: | |
| (require 'plz) | |
| (defvar voicevox-audio-file "test.wav") | |
| (defvar voicevox-current-sentense "?????") | |
| (defun voicevox-set (&optional sentence) | |
| (interactive "s") | |
| (setq voicevox-current-sentense sentence)) | |
| (defun voicevox-set-region (&optional beg end) | |
| (interactive "r") | |
| (setq voicevox-current-sentense (buffer-substring-no-properties beg end))) | |
| (defun voicevox-play () | |
| (interactive) | |
| (voicevox-cleint-fetch-audio-query)) | |
| ;------------------------------------------------------------------- | |
| (defvar voicevox-server-buffer-name "*VOICEVOX SERVER*") | |
| (defvar voicevox-server-command | |
| '("docker" "run" "--rm" "-it" "-p" "127.0.0.1:50021:50021" "voicevox/voicevox_engine:cpu-ubuntu20.04-latest")) | |
| (defvar voicevox-server-stop-signal-code 15) ;; SIGTERM | |
| (defun voicevox-server-start () | |
| (interactive) | |
| (make-process :name "VOICEBOX SERVER" | |
| :buffer voicevox-server-buffer-name | |
| :command voicevox-server-command)) | |
| (defun voicevox-server-stop () | |
| (interactive) | |
| (signal-process | |
| (get-buffer-process (get-buffer voicevox-server-buffer-name)) | |
| voicevox-server-stop-signal-code)) | |
| ;------------------------------------------------------------------- | |
| (require 'plz) | |
| (require 'json) | |
| (defvar voicevox-client-request-synthesis-param nil) | |
| (setq voicevox-client-fetch-audio-query-success-hook nil) | |
| (setq voicevox-client-fetch-synthesis-success-hook nil) | |
| (defun voicevox-cleint-fetch-audio-query () | |
| (interactive) | |
| (plz 'post (format | |
| "http://localhost:50021/audio_query?speaker=1&text=%s" | |
| (url-encode-url voicevox-current-sentense)) | |
| :headers '(("Content-Type" . "application/json")) | |
| :body "" | |
| :then (lambda (d) | |
| (setq voicevox-client-request-synthesis-param d) | |
| (run-hooks 'voicevox-client-fetch-audio-query-success-hook)))) | |
| (defun voicevox-cleint-fetch-audio-file () | |
| (interactive) | |
| (let ((plz-curl-default-args | |
| (append `("-o" ,voicevox-audio-file) plz-curl-default-args))) | |
| (plz 'post "http://localhost:50021/synthesis?speaker=1" | |
| :headers '(("Content-Type" . "application/json")) | |
| :body voicevox-client-request-synthesis-param | |
| :then (lambda (d) | |
| (run-hooks 'voicevox-client-fetch-synthesis-success-hook))))) | |
| ;------------------------------------------------------------------- | |
| (defvar voicevox-afplay-executable "afplay") | |
| (defvar voicevox-afplay-buffer-name "*VOICEBOX AFPLAY*") | |
| (defun voicevox-afplay () | |
| (interactive) | |
| (make-process :name "VOICEBOX" | |
| :buffer voicevox-afplay-buffer-name | |
| :command `(,voicevox-afplay-executable ,voicevox-audio-file))) | |
| ;------------------------------------------------------------------- | |
| (add-hook 'voicevox-client-fetch-audio-query-success-hook 'voicevox-cleint-fetch-audio-file) | |
| (add-hook 'voicevox-client-fetch-synthesis-success-hook 'voicevox-afplay) | |
| ;;;###autoload | |
| (defvar voicevox-core-process nil) | |
| ;;;###autoload | |
| (defun voicevox-core-start () | |
| "voicevox_core?????????????????" | |
| (interactive) | |
| (unless (process-live-p voicevox-core-process) ; ????????????????? | |
| (setq voicevox-core-process | |
| (start-process "*VOICEVOX*" (get-buffer-create "*VOICEVOX*") | |
| (expand-file-name "~/.cache/python-venvs/speech/bin/python") | |
| (expand-file-name "~/ng/symdon/articles/posts/1673875278/speech1.py"))))) | |
| ;;;###autoload | |
| (defun voicevox-say-on-region () | |
| "???????????????" | |
| (interactive) | |
| (process-send-string voicevox-core-process (buffer-substring-no-properties (region-beginning) (region-end))) | |
| (process-send-string voicevox-core-process "")) | |
| (provide 'voicevox) | |
| ;; voicevox.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment