venice.ai TTS

fukurou

the supreme coder
ADMIN
Alright, you asked for the full “shit in the ass walkthrough,” so buckle up—we’re going full throttle on this one. Here’s your no-BS, step-by-step guide to sending a string to Venice AI’s Text-to-Speech API and blasting it through your laptop speakers using Python.




💣 The Full Walkthrough: Venice TTS in Python​


🧠 What You’re Doing​


You’re writing a Python script that:


  1. Takes a string of text.
  2. Sends it to Venice AI’s /audio/speech endpoint.
  3. Gets back an MP3 file.
  4. Plays it out loud using your laptop speakers.



🛠️ Step 1: Install the Required Packages​


Open your terminal and run:

pip install requests pydub simpleaudio


  • requests: sends the HTTP request to Venice.
  • pydub: handles audio conversion.
  • simpleaudio: plays the sound.

If you’re on Linux, you might also need ffmpeg installed for pydub to work:

sudo apt install ffmpeg




🔑 Step 2: Get Your API Key​





🧾 Step 3: Write the Python Script​


Here’s the full code with zero magic hidden:

Python:
import requests
from pydub import AudioSegment
import simpleaudio as sa
import io

# 🔐 Your API key from Venice
API_KEY = "your_api_key_here"

# 🗣️ The string you want spoken
text_to_speak = "This is the string that will be spoken out loud."

# 📦 Venice TTS request payload
payload = {
    "input": text_to_speak,
    "model": "tts-kokoro",              # Venice’s default TTS model
    "response_format": "mp3",           # You can also use wav, flac, etc.
    "speed": 1,                         # 1 = normal speed; range is 0.25 to 4.0
    "streaming": False,                 # False = get full audio file
    "voice": "bella"                    # Use Bella voice from Kokoro TTS
}

# 🚀 Send the request to Venice
response = requests.post(
    "https://api.venice.ai/api/v1/audio/speech",
    headers={
        "Authorization": f"Bearer {API_KEY}",
        "Content-Type": "application/json"
    },
    json=payload
)

# 🧠 Check for errors
if response.status_code != 200:
    print(f"Error: {response.status_code} - {response.text}")
    exit()

# 🎧 Convert MP3 response to audio segment
audio = AudioSegment.from_file(io.BytesIO(response.content), format="mp3")

# 🔊 Play the audio through your speakers
play_obj = sa.play_buffer(
    audio.raw_data,
    num_channels=audio.channels,
    bytes_per_sample=audio.sample_width,
    sample_rate=audio.frame_rate
)
play_obj.wait_done()




🧪 Step 4: Run It​


Save the script as speak.py, then run:

python speak.py


Your laptop should speak the string you entered. If it doesn’t, check:


  • Your speaker volume.
  • Whether ffmpeg is installed.
  • That your API key is valid.



🎨 Bonus: Customize the Voice​


Venice offers a ton of voices like:


  • am_liam (male, American)
  • af_nova (female, futuristic)
  • bf_emma (British female)
  • jf_nezumi (Japanese anime-style)

Just swap "voice": "af_sky" with your pick from the official voice list.
 
Last edited:

fukurou

the supreme coder
ADMIN
venice.ai TTS:
add requirements.txt :
Code:
requests
pydub
simpleaudio
pygame

Python:
import requests
import os
import threading
from DLC.api_keys import VENICE_API_KEY
from LivinGrimoirePacket.AXPython import DrawRnd
from LivinGrimoirePacket.LivinGrimoire import Skill

os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "1"
import pygame

class BellaTTS:
    def __init__(self):
        pygame.init()
        pygame.mixer.init()
        self.apikey: str = VENICE_API_KEY
        self.voice = 'bella'
        self.model = 'tts-kokoro'
        self.speed = 1
        self.url = "https://api.venice.ai/api/v1/audio/speech"
        # Ensure sounds/ directory exists
        os.makedirs("sounds", exist_ok=True)


    @staticmethod
    def __play_file(txt: str, voice: str):
        sound = pygame.mixer.Sound(f'sounds/{voice}_{txt}.mp3')
        sound.play()
        while pygame.mixer.get_busy():
            pygame.time.delay(100)

    def setVoice(self, newVoice: str):
        self.voice = newVoice

    def speak(self, txt: str):
        if len(txt) > 242:
            return
        file_name = self.__sanitize_filename(txt)
        path = f'sounds/{self.voice}_{file_name}.mp3'
        if os.path.isfile(path):
            threading.Thread(target=self.__play_file, args=(file_name, self.voice), daemon=True).start()
        else:
            threading.Thread(target=self.__create_and_playFile, args=(txt,), daemon=True).start()

    def __create_and_playFile(self, txt: str):
        file_name = self.__sanitize_filename(txt)
        payload = {
            "input": txt,
            "model": self.model,
            "response_format": "mp3",
            "speed": self.speed,
            "streaming": False,
            "voice": self.voice
        }
        headers = {
            "Authorization": f"Bearer {self.apikey}",
            "Content-Type": "application/json"
        }
        response = requests.post(self.url, headers=headers, json=payload)
        if response.status_code == 200:
            with open(f'sounds/{self.voice}_{file_name}.mp3', 'wb') as f:
                f.write(response.content)
            self.__play_file(file_name, self.voice)

    @staticmethod
    def __sanitize_filename(txt: str) -> str:
        return txt.translate(str.maketrans('', '', "?':,\n"))

class DiTTS_venice(Skill):
    def __init__(self):
        super().__init__()
        self.set_skill_type(3)
        self.set_skill_lobe(2)
        self.speech: BellaTTS = BellaTTS()
        self.voices: DrawRnd = DrawRnd("bella", "af_nova", "bf_emma")
        self.speech.setVoice(self.voices.renewableDraw())

    def input(self, ear: str, skin: str, eye: str):
        if not ear:
            return
        if ear == "change voice":
            self.speech.setVoice(self.voices.renewableDraw())
            self.speech.speak("my voice has been changed")
        else:
            self.speech.speak(ear)

🛠 Setup Notes:

  • Create a sounds/ folder next to your main script.
  • Replace VENICE_API_KEY with your actual key in DLC/api_keys.py.
  • You can expand the DrawRnd pool with more Venice voices from their official list.
 
Last edited:

fukurou

the supreme coder
ADMIN
Code:
# Female Venice TTS Voices (for DrawRnd):
# ---------------------------------------
# "bella"       # Expressive default female voice
# "af_nova"     # African-accented female voice
# "bf_emma"     # British-accented female voice
# "bf_sophia"   # British-accented female, soft tone
# "bf_grace"    # British-accented female, formal
# "am_olivia"   # American-accented female, upbeat
# "jp_hana"     # Japanese-accented female voice
# "es_carla"    # Spanish-accented female voice
# "fr_claire"   # French-accented female voice
# "de_lena"     # German-accented female voice
 
Top