morshu-server: use resolved absolute paths and pass env properly
This commit is contained in:
@@ -3,18 +3,22 @@
|
|||||||
Morshu TTS Server — standalone HTTP API for MorshuTalk engine.
|
Morshu TTS Server — standalone HTTP API for MorshuTalk engine.
|
||||||
Runs on port 3002. GET /say?text=... returns WAV audio.
|
Runs on port 3002. GET /say?text=... returns WAV audio.
|
||||||
"""
|
"""
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import io
|
import io
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||||
from urllib.parse import urlparse, parse_qs
|
from urllib.parse import urlparse, parse_qs
|
||||||
|
|
||||||
# Add ttstoy to path so we can import the engine
|
# Add ttstoy root to path so we can import the engine
|
||||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
SCRIPT_DIR = Path(__file__).resolve().parent
|
||||||
|
TTSTOY_DIR = SCRIPT_DIR.parent
|
||||||
|
sys.path.insert(0, str(TTSTOY_DIR))
|
||||||
|
|
||||||
from morshutalk_engine import Morshu
|
from morshutalk_engine import Morshu
|
||||||
|
|
||||||
morshu = Morshu()
|
morshu = Morshu()
|
||||||
PORT = 3002
|
PORT = int(os.environ.get("PORT", 3002))
|
||||||
|
|
||||||
|
|
||||||
class Handler(BaseHTTPRequestHandler):
|
class Handler(BaseHTTPRequestHandler):
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
|
|
||||||
echo "🗣️ Starting Morshu TTS Server..."
|
echo "🗣️ Starting Morshu TTS Server..."
|
||||||
|
|
||||||
cd "$(dirname "$0")"
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
cd "$SCRIPT_DIR"
|
||||||
|
|
||||||
# Check if python3 is available
|
# Check if python3 is available
|
||||||
if ! command -v python3 &> /dev/null; then
|
if ! command -v python3 &> /dev/null; then
|
||||||
@@ -22,12 +23,13 @@ for pkg in pydub nltk g2p_en numpy; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
# Check if the morshu wav file exists
|
# Check if the morshu wav file exists
|
||||||
if [ ! -f "../morshutalk_morshu.wav" ]; then
|
if [ ! -f "$SCRIPT_DIR/../morshutalk_morshu.wav" ]; then
|
||||||
echo "❌ Error: morshutalk_morshu.wav not found in parent directory"
|
echo "❌ Error: morshutalk_morshu.wav not found in parent directory"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Start the server
|
# Start the server
|
||||||
echo "✅ Starting server on port ${PORT:-3002}..."
|
export PORT="${PORT:-3002}"
|
||||||
|
echo "✅ Starting server on port $PORT..."
|
||||||
echo "🗣️ Using MorshuTalk engine"
|
echo "🗣️ Using MorshuTalk engine"
|
||||||
exec python3 server.py
|
exec python3 "$SCRIPT_DIR/server.py"
|
||||||
|
|||||||
+14
-2
@@ -523,6 +523,10 @@ class TtsToy(Cog):
|
|||||||
log.info("Morshu server already running")
|
log.info("Morshu server already running")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
if not self.morshu_dir.exists():
|
||||||
|
log.error(f"Morshu server directory not found: {self.morshu_dir}")
|
||||||
|
return False
|
||||||
|
|
||||||
server_py = self.morshu_dir / "server.py"
|
server_py = self.morshu_dir / "server.py"
|
||||||
if not server_py.exists():
|
if not server_py.exists():
|
||||||
log.error(f"Morshu server not found: {server_py}")
|
log.error(f"Morshu server not found: {server_py}")
|
||||||
@@ -533,7 +537,7 @@ class TtsToy(Cog):
|
|||||||
|
|
||||||
self.morshu_process = await asyncio.to_thread(
|
self.morshu_process = await asyncio.to_thread(
|
||||||
subprocess.Popen,
|
subprocess.Popen,
|
||||||
[sys.executable, "server.py"],
|
[sys.executable, str(server_py)],
|
||||||
cwd=str(self.morshu_dir),
|
cwd=str(self.morshu_dir),
|
||||||
env=env,
|
env=env,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
@@ -541,10 +545,18 @@ class TtsToy(Cog):
|
|||||||
text=True
|
text=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Wait for server to start
|
||||||
await asyncio.sleep(3)
|
await asyncio.sleep(3)
|
||||||
|
|
||||||
|
# Check if it's still running
|
||||||
if self.morshu_process.poll() is not None:
|
if self.morshu_process.poll() is not None:
|
||||||
log.error("Morshu server failed to start")
|
stderr = self.morshu_process.stderr.read()
|
||||||
|
stdout = self.morshu_process.stdout.read()
|
||||||
|
log.error(f"Morshu server failed to start (exit {self.morshu_process.returncode})")
|
||||||
|
if stderr:
|
||||||
|
log.error(f"Morshu stderr: {stderr}")
|
||||||
|
if stdout:
|
||||||
|
log.error(f"Morshu stdout: {stdout}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
log.info(f"Morshu server started on port {self.morshu_port}")
|
log.info(f"Morshu server started on port {self.morshu_port}")
|
||||||
|
|||||||
Reference in New Issue
Block a user