0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

voicevox web api v1を利用してテキストファイルを音声に変換するスクリプト 'yurie.py'

Last updated at Posted at 2024-09-26

タイトル通りです。今はv3が出ていますが、v1になってるのは、v3は認証が必要なので。

yurie.py
import requests
import json
import time
sid=0
file_name = "sample.mp3"

def generate_audio(text):
    url = f"https://api.tts.quest/v1/voicevox?text={text}&speaker={sid}"
    response = requests.get(url).json()
    while True:
        statusurl=response["audioStatusUrl"]
        status=requests.get(statusurl).json()
        if status["isAudioReady"]:
            break
        time.sleep(1)

    audio_url = response["mp3DownloadUrl"]
    return audio_url

def save_audio(audio_url, file_name):
    audio_content = requests.get(audio_url).content
    with open(file_name, "wb") as file:
        file.write(audio_content)

def main():
    f=open(input("Input file name to speak:"),"rt")
    text = f.read().replace(' ','').replace('\t','').replace('\n','')

    print(text)
    audio_url = generate_audio(text)
    print(audio_url)
    save_audio(audio_url, file_name)

if __name__ == "__main__":
    main()
    exit(0)
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?