- PHP fa la seva feina (interfície, configuració, etc.).
- Python està sempre en segon pla, monitorant el porta-retalls i parlant.
Exemple de control via fitxer:
<?php
file_put_contents("config.txt", "start"); // O "stop"
?>
Python (modificat):
import pyperclip
import pyttsx3
import time
import os
engine = pyttsx3.init()
last_text = ""
while True:
if os.path.exists("config.txt"):
with open("config.txt") as f:
state = f.read().strip()
if state != "start":
time.sleep(1)
continue
text = pyperclip.paste()
if text != last_text and text.strip() != "":
print("Nou text copiat:", text)
engine.say(text)
engine.runAndWait()
last_text = text
time.sleep(0.5)
- 🛠️ Etapa 1: Crear el lector en Python
- ✅ Script Python que detecta el text copiat.
- ✅ Converteix el text en veu (TTS).
- ✅ Opció per controlar l’activació (fitxer
config.txt
).
- 🛠️ Etapa 2: Crear una interfície bàsica en PHP
- ✅ Botons per activar o desactivar la lectura.
- ✅ Escriure a
config.txt
segons l’acció.
- 🛠️ Etapa 3: Integració
- ✅ Gestionar l’estat des de la interfície.
- ✅ Executar el script Python des de PHP si cal.
'Etapa 1: lector en Python
import pyperclip
import pyttsx3
import time
import os
engine = pyttsx3.init()
last_text = ""
def llegir_text(text):
engine.say(text)
engine.runAndWait()
while True:
# Llegim l'estat del fitxer de configuració
if os.path.exists("config.txt"):
with open("config.txt") as f:
estat = f.read().strip()
if estat != "start":
time.sleep(1)
continue
else:
time.sleep(1)
continue
# Llegim el text del porta-retalls
text = pyperclip.paste()
if text != last_text and text.strip() != "":
print("Llegint:", text)
llegir_text(text)
last_text = text
time.sleep(0.5)