Skip to content

Instantly share code, notes, and snippets.

@MayamaTakeshi
Created November 26, 2023 07:08
Show Gist options
  • Save MayamaTakeshi/91a81bdf957be4a6f5db69f8f8d0d913 to your computer and use it in GitHub Desktop.
Save MayamaTakeshi/91a81bdf957be4a6f5db69f8f8d0d913 to your computer and use it in GitHub Desktop.
Speak japanese text copied to clipboard
import time
import pyperclip
import pyopenjtalk
import numpy as np
import sounddevice as sd
# Get initial clipboard content
previous_content = ""
while True:
# Get current clipboard content
current_content = pyperclip.paste()
# Check if clipboard content has changed
if current_content != previous_content:
print(f"{current_content}")
x, sr = pyopenjtalk.tts(f"{current_content}")
# Play the audio
sd.play(x.astype(np.int16), samplerate=sr)
sd.wait()
# Update previous content to current content
previous_content = current_content
time.sleep(0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment