forked from zaigie/FunSpeech
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
63 lines (51 loc) · 1.65 KB
/
Copy pathmain.py
File metadata and controls
63 lines (51 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# -*- coding: utf-8 -*-
"""
FunSpeech API 主程序
"""
import socket
import uvicorn
import logging
from app.main import create_app
from app.core.config import settings
# 创建应用实例
app = create_app()
logger = logging.getLogger(__name__)
def find_free_port(start_port: int, max_attempts: int = 100) -> int:
"""
Find a free port starting from start_port
Args:
start_port: Starting port number
max_attempts: Maximum number of ports to try
Returns:
Available port number
"""
for port in range(start_port, start_port + max_attempts):
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(("", port))
return port
except OSError:
continue
raise RuntimeError(f"Could not find a free port after {max_attempts} attempts")
if __name__ == "__main__":
# Try to find an available port
try:
port = find_free_port(settings.PORT)
if port != settings.PORT:
logger.warning(f"Port {settings.PORT} is already in use, using port {port} instead")
except RuntimeError as e:
logger.error(str(e))
port = settings.PORT
logger.info("启动FunSpeech API服务器")
logger.info(
f"服务器配置: Host={settings.HOST}, Port={port}, Debug={settings.DEBUG}"
)
logger.info(f"GPU配置: ASR_GPUS={settings.ASR_GPUS or '(auto)'}, TTS_GPUS={settings.TTS_GPUS or '(auto)'}")
uvicorn.run(
"main:app",
host=settings.HOST,
port=port,
reload=settings.DEBUG,
log_level=settings.LOG_LEVEL.lower(),
access_log=True,
)