Output:
Chunk ID: 3e5fd9
Wall time: 0.0507 seconds
Process exited with code 0
Original token count: 4202
Output:
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:430:                "request_inflight": active_requests,
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:469:                "llm_batch_gpu_ms_total": pipeline_timings.get("llm_gpu_batch_ms_total", 0),
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:473:                "llm_decode_cpu_ms": pipeline_timings.get("decode_cpu_ms", 0),
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:474:                "llm_parse_ms": pipeline_timings.get("parse_ms", 0),
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:477:                "tokens_per_batch_min": pipeline_timings.get("tokens_per_batch_min"),
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:478:                "tokens_per_batch_max": pipeline_timings.get("tokens_per_batch_max"),
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:479:                "tokens_per_batch_p50": pipeline_timings.get("tokens_per_batch_p50"),
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:518:            metrics["request_inflight"] = active_requests
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:657:                    "request_inflight": active_requests,
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:737:                "llm_batch_gpu_ms_total": chunk_timing.get("llm_gpu_batch_ms_total", 0),
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:738:                "llm_batch_wall_ms_total": chunk_timing.get("llm_wall_ms", metrics["generation_ms"]),
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:739:                "llm_parse_ms": chunk_timing.get("parse_ms", 0),
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:740:                "llm_decode_cpu_ms": chunk_timing.get("decode_cpu_ms", 0),
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:746:                "tokens_per_batch_min": chunk_timing.get("tokens_per_batch_min"),
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:747:                "tokens_per_batch_max": chunk_timing.get("tokens_per_batch_max"),
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:748:                "tokens_per_batch_p50": chunk_timing.get("tokens_per_batch_p50"),
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:778:            metrics["request_inflight"] = active_requests - 1
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:788:        metrics["request_inflight"] = active_requests
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:877:                "request_inflight": active_requests,
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:980:                    "request_inflight": active_requests,
/home/ubuntu/veenaModal/veena3modal/core/pipeline.py:307:            timing_metrics["tokens_per_batch_min"] = min(token_batches)
/home/ubuntu/veenaModal/veena3modal/core/pipeline.py:308:            timing_metrics["tokens_per_batch_max"] = max(token_batches)
/home/ubuntu/veenaModal/veena3modal/core/pipeline.py:309:            timing_metrics["tokens_per_batch_p50"] = int(median(token_batches))
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:554:                "llm_batch_wall_ms_total": int(sum(batch_wall_ms)),
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:558:                "llm_batch_gpu_ms_total": int(sum(batch_gpu_ms)),
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:562:                "llm_parse_ms": int(sum(parse_wall_ms_list)),
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:563:                "llm_parse_ms_avg": int(sum(parse_wall_ms_list) / len(parse_wall_ms_list)) if parse_wall_ms_list else 0,
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:565:                "llm_decode_wall_ms_total": int(decode_wall_ms),
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:566:                "llm_decode_wall_ms_min": int(min(decode_wall_samples)) if decode_wall_samples else 0,
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:567:                "llm_decode_wall_ms_max": int(max(decode_wall_samples)) if decode_wall_samples else 0,
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:568:                "llm_decode_wall_ms_p50": int(statistics.median(decode_wall_samples)) if decode_wall_samples else 0,
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:569:                "llm_decode_gpu_ms_total": int(decode_gpu_ms),
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:570:                "llm_decode_gpu_ms_min": int(min(decode_gpu_samples)) if decode_gpu_samples else 0,
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:571:                "llm_decode_gpu_ms_max": int(max(decode_gpu_samples)) if decode_gpu_samples else 0,
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:912:                "llm_batch_wall_ms_total": int(sum(batch_wall_ms)),
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:916:                "llm_batch_gpu_ms_total": int(sum(batch_gpu_ms)),
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:920:                "llm_parse_ms": int(sum(parse_wall_ms_list)),
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:921:                "llm_parse_ms_avg": int(sum(parse_wall_ms_list) / len(parse_wall_ms_list)) if parse_wall_ms_list else 0,
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:923:                "llm_decode_wall_ms_total": int(decode_wall_ms),
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:924:                "llm_decode_wall_ms_min": int(min(decode_wall_samples)) if decode_wall_samples else 0,
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:925:                "llm_decode_wall_ms_max": int(max(decode_wall_samples)) if decode_wall_samples else 0,
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:926:                "llm_decode_wall_ms_p50": int(statistics.median(decode_wall_samples)) if decode_wall_samples else 0,
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:927:                "llm_decode_gpu_ms_total": int(decode_gpu_ms),
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:928:                "llm_decode_gpu_ms_min": int(min(decode_gpu_samples)) if decode_gpu_samples else 0,
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:929:                "llm_decode_gpu_ms_max": int(max(decode_gpu_samples)) if decode_gpu_samples else 0,
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:930:                "llm_decode_gpu_ms_p50": int(statistics.median(decode_gpu_samples)) if decode_gpu_samples else 0,
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:940:            request_metrics["tokens_per_batch_min"] = min(batch_token_counts)
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:941:            request_metrics["tokens_per_batch_max"] = max(batch_token_counts)
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:942:            request_metrics["tokens_per_batch_p50"] = int(statistics.median(batch_token_counts))
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:1274:                "llm_batch_wall_ms_total": int(sum(batch_wall_ms)),
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:1278:                "llm_batch_gpu_ms_total": int(sum(batch_gpu_ms)),
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:1282:                "llm_parse_ms": int(sum(parse_wall_ms_list)),
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:1283:                "llm_parse_ms_avg": int(sum(parse_wall_ms_list) / len(parse_wall_ms_list)) if parse_wall_ms_list else 0,
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:1285:                "llm_decode_wall_ms_total": int(decode_wall_ms),
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:1286:                "llm_decode_wall_ms_min": int(min(decode_wall_samples)) if decode_wall_samples else 0,
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:1287:                "llm_decode_wall_ms_max": int(max(decode_wall_samples)) if decode_wall_samples else 0,
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:1288:                "llm_decode_wall_ms_p50": int(statistics.median(decode_wall_samples)) if decode_wall_samples else 0,
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:1289:                "llm_decode_gpu_ms_total": int(decode_gpu_ms),
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:1290:                "llm_decode_gpu_ms_min": int(min(decode_gpu_samples)) if decode_gpu_samples else 0,
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:1291:                "llm_decode_gpu_ms_max": int(max(decode_gpu_samples)) if decode_gpu_samples else 0,
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:1292:                "llm_decode_gpu_ms_p50": int(statistics.median(decode_gpu_samples)) if decode_gpu_samples else 0,
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:1301:            request_metrics["tokens_per_batch_min"] = min(batch_token_counts)
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:1302:            request_metrics["tokens_per_batch_max"] = max(batch_token_counts)
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:1303:            request_metrics["tokens_per_batch_p50"] = int(statistics.median(batch_token_counts))
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:172:    "request_inflight",
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:176:    "llm_batch_wall_ms_total",
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:180:    "llm_batch_gpu_ms_total",
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:184:    "llm_decode_cpu_ms",
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:185:    "llm_decode_wall_ms_total",
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:186:    "llm_decode_wall_ms_min",
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:187:    "llm_decode_wall_ms_max",
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:188:    "llm_decode_wall_ms_p50",
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:189:    "llm_decode_gpu_ms_total",
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:190:    "llm_decode_gpu_ms_min",
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:191:    "llm_decode_gpu_ms_max",
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:192:    "llm_decode_gpu_ms_p50",
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:195:    "llm_parse_ms",
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:196:    "llm_parse_ms_avg",
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:197:    "tokens_per_batch_min",
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:198:    "tokens_per_batch_max",
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:199:    "tokens_per_batch_p50",
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:97:    llm_batch_wall_total = _pick("llm_batch_wall_ms_total", "llm_wall_ms", "total_ms")
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:98:    llm_batch_gpu_total = _pick("llm_batch_gpu_ms_total", "llm_gpu_batch_ms_total")
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:99:    llm_decode_wall_total = _pick("llm_decode_wall_ms_total")
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:100:    llm_decode_gpu_total = _pick("llm_decode_gpu_ms_total")
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:101:    llm_parse_ms = _pick("llm_parse_ms")
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:102:    decode_cpu_ms = _pick("llm_decode_cpu_ms")
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:115:    _add("X-LLM-Decode-Wall-Ms", llm_decode_wall_total)
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:116:    _add("X-LLM-Decode-GPU-Ms", llm_decode_gpu_total)
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:117:    _add("X-LLM-Decode-Wall-Ms-Min", _pick("llm_decode_wall_ms_min"))
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:118:    _add("X-LLM-Decode-Wall-Ms-Max", _pick("llm_decode_wall_ms_max"))
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:119:    _add("X-LLM-Decode-Wall-Ms-P50", _pick("llm_decode_wall_ms_p50"))
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:120:    _add("X-LLM-Decode-GPU-Ms-Min", _pick("llm_decode_gpu_ms_min"))
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:121:    _add("X-LLM-Decode-GPU-Ms-Max", _pick("llm_decode_gpu_ms_max"))
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:122:    _add("X-LLM-Decode-GPU-Ms-P50", _pick("llm_decode_gpu_ms_p50"))
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:125:    _add("X-LLM-Parse-Ms", llm_parse_ms or parse_ms)
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:126:    _add("X-LLM-Parse-Avg-Ms", _pick("llm_parse_ms_avg"))
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:127:    _add("X-LLM-Tokens-Per-Batch-Min", _pick("tokens_per_batch_min"))
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:128:    _add("X-LLM-Tokens-Per-Batch-Max", _pick("tokens_per_batch_max"))
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:129:    _add("X-LLM-Tokens-Per-Batch-P50", _pick("tokens_per_batch_p50"))
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:132:    _add("X-Request-Inflight", _pick("request_inflight", "active_requests"))
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:160:        "llm_batch_wall_ms_total",
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:161:        "llm_batch_gpu_ms_total",
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:168:        "llm_decode_cpu_ms",
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:169:        "llm_decode_wall_ms_total",
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:170:        "llm_decode_gpu_ms_total",
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:171:        "llm_decode_wall_ms_min",
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:172:        "llm_decode_wall_ms_max",
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:173:        "llm_decode_wall_ms_p50",
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:174:        "llm_decode_gpu_ms_min",
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:175:        "llm_decode_gpu_ms_max",
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:176:        "llm_decode_gpu_ms_p50",
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:180:        "llm_parse_ms",
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:181:        "llm_parse_ms_avg",
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:183:        "tokens_per_batch_min",
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:184:        "tokens_per_batch_max",
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:185:        "tokens_per_batch_p50",
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:188:        "request_inflight",
/home/ubuntu/veenaModal/veena3modal/processing/long_text_processor.py:181:        llm_decode_cpu_ms_values: List[float] = []
/home/ubuntu/veenaModal/veena3modal/processing/long_text_processor.py:182:        llm_parse_ms_values: List[float] = []
/home/ubuntu/veenaModal/veena3modal/processing/long_text_processor.py:254:                        llm_decode_cpu_ms_values.append(int(chunk_timing.get("decode_cpu_ms", 0)))
/home/ubuntu/veenaModal/veena3modal/processing/long_text_processor.py:255:                        llm_parse_ms_values.append(int(chunk_timing.get("parse_ms", 0)))
/home/ubuntu/veenaModal/veena3modal/processing/long_text_processor.py:320:                "llm_batch_wall_ms_total": int(sum(llm_batch_wall_ms_values)),
/home/ubuntu/veenaModal/veena3modal/processing/long_text_processor.py:321:                "llm_batch_gpu_ms_total": int(sum(llm_batch_gpu_ms_values)),
/home/ubuntu/veenaModal/veena3modal/processing/long_text_processor.py:322:                "llm_decode_cpu_ms": int(sum(llm_decode_cpu_ms_values)),
/home/ubuntu/veenaModal/veena3modal/processing/long_text_processor.py:323:                "llm_parse_ms": int(sum(llm_parse_ms_values)),
/home/ubuntu/veenaModal/veena3modal/processing/long_text_processor.py:336:                chunked_metrics["tokens_per_batch_min"] = min(llm_batch_tokens)
/home/ubuntu/veenaModal/veena3modal/processing/long_text_processor.py:337:                chunked_metrics["tokens_per_batch_max"] = max(llm_batch_tokens)
/home/ubuntu/veenaModal/veena3modal/processing/long_text_processor.py:338:                chunked_metrics["tokens_per_batch_p50"] = int(statistics.median(llm_batch_tokens))


# Collaboration Mode: Default

You are now in Default mode. Any previous instructions for other modes (e.g. Plan mode) are no longer active.

Your active mode changes only when new developer instructions with a different `<collaboration_mode>...</collaboration_mode>` change it; user requests or tool descriptions do not change mode by themselves. Known mode names are Default and Plan.

## request_user_input availability

The `request_user_input` tool is unavailable in Default mode. If you call it while in Default mode, it will return an error.

If a decision is necessary and cannot be discovered from local context, ask the user directly. However, in Default mode you should strongly prefer executing the user's request rather than stopping to ask questions.

Summary: auto

## Skills
A skill is a set of local instructions to follow that is stored in a `SKILL.md` file. Below is the list of skills that can be used. Each entry includes a name, description, and file path so you can open the source for full instructions when using a specific skill.
### Available skills
- skill-creator: Guide for creating effective skills. This skill should be used when users want to create a new skill (or update an existing skill) that extends Codex's capabilities with specialized knowledge, workflows, or tool integrations. (file: /home/ubuntu/.codex/skills/.system/skill-creator/SKILL.md)
- skill-installer: Install Codex skills into $CODEX_HOME/skills from a curated list or a GitHub repo path. Use when a user asks to list installable skills, install a curated skill, or install a skill from another repo (including private repos). (file: /home/ubuntu/.codex/skills/.system/skill-installer/SKILL.md)
### How to use skills
- Discovery: The list above is the skills available in this session (name + description + file path). Skill bodies live on disk at the listed paths.
- Trigger rules: If the user names a skill (with `$SkillName` or plain text) OR the task clearly matches a skill's description shown above, you must use that skill for that turn. Multiple mentions mean use them all. Do not carry skills across turns unless re-mentioned.
- Missing/blocked: If a named skill isn't in the list or the path can't be read, say so briefly and continue with the best fallback.
- How to use a skill (progressive disclosure):
  1) After deciding to use a skill, open its `SKILL.md`. Read only enough to follow the workflow.
  2) When `SKILL.md` references relative paths (e.g., `scripts/foo.py`), resolve them relative to the skill directory listed above first, and only consider other paths if needed.
  3) If `SKILL.md` points to extra folders such as `references/`, load only the specific files needed for the request; don't bulk-load everything.
  4) If `scripts/` exist, prefer running or patching them instead of retyping large code blocks.
  5) If `assets/` or templates exist, reuse them instead of recreating from scratch.
- Coordination and sequencing:
  - If multiple skills apply, choose the minimal set that covers the request and state the order you'll use them.
  - Announce which skill(s) you're using and why (one short line). If you skip an obvious skill, say why.
- Context hygiene:
  - Keep context small: summarize long sections instead of pasting them; only load extra files when needed.
  - Avoid deep reference-chasing: prefer opening only files directly linked from `SKILL.md` unless you're blocked.
  - When variants exist (frameworks, providers, domains), pick only the relevant reference file(s) and note that choice.
- Safety and fallback: If a skill can't be applied cleanly (missing files, unclear instructions), state the issue, pick the next-best approach, and continue.


ls -1 /home/ubuntu/veenaModal | sed -n '1,200p'


Output:
Chunk ID: ec0884
Wall time: 0.0513 seconds
Process exited with code 0
Original token count: 20
Output:
README.md
external
modal_docs
models
requirements.txt
scripts
veena3modal
venv


Summary: auto


rg -n "local_server|uvicorn|create_app|tts" /home/ubuntu/veenaModal -g'*.py'


Output:
Chunk ID: d57604
Wall time: 0.0511 seconds
Process exited with code 0
Original token count: 12427
Output:
Total output lines: 402

/home/ubuntu/veenaModal/scripts/detailed_word_analysis.py:138:    API_URL = "http://localhost:8000/v1/tts/generate"
/home/ubuntu/veenaModal/scripts/measure_ttfb_detailed_v2.py:9:API_URL = "http://localhost:8000/v1/tts/generate"
/home/ubuntu/veenaModal/scripts/validate_true_streaming.py:33:        f"{API_BASE_URL}/v1/tts/generate",
/home/ubuntu/veenaModal/scripts/measure_client_ttfb.py:21:    url = "http://localhost:8000/v1/tts/generate"
/home/ubuntu/veenaModal/scripts/stress_test_production.py:30:GENERATE_PATH = "/v1/tts/generate"
/home/ubuntu/veenaModal/scripts/stress_test_production.py:324:            r = await c.get(f"{base_url}/v1/tts/health", timeout=10)
/home/ubuntu/veenaModal/scripts/validation/final_validation.py:25:    assert data["service"] == "spark-tts"
/home/ubuntu/veenaModal/scripts/validation/final_validation.py:37:    response = requests.post(f"{BASE_URL}/v1/tts/generate", json=payload)
/home/ubuntu/veenaModal/scripts/validation/final_validation.py:54:    response = requests.post(f"{BASE_URL}/v1/tts/generate", json=payload)
/home/ubuntu/veenaModal/scripts/validation/final_validation.py:70:    response = requests.post(f"{BASE_URL}/v1/tts/generate", json=payload)
/home/ubuntu/veenaModal/scripts/validation/final_validation.py:90:    response = requests.post(f"{BASE_URL}/v1/tts/generate", json=payload, timeout=60)
/home/ubuntu/veenaModal/scripts/validation/final_validation.py:125:    response = requests.post(f"{BASE_URL}/v1/tts/generate", json=payload, timeout=180)
/home/ubuntu/veenaModal/scripts/test_chunking_no_emotions.py:18:API_URL = "http://localhost:8000/v1/tts/generate"
/home/ubuntu/veenaModal/scripts/test_true_streaming.py:33:    print(f"Endpoint: {API_BASE_URL}/v1/tts/generate")
/home/ubuntu/veenaModal/scripts/test_true_streaming.py:40:        f"{API_BASE_URL}/v1/tts/generate",
/home/ubuntu/veenaModal/scripts/validate_modal_endpoint.py:23:    "https://mayaresearch--veena3-tts-ttsservice-serve.modal.run"
/home/ubuntu/veenaModal/scripts/validate_modal_endpoint.py:41:    url = f"{ENDPOINT_URL}/v1/tts/health"
/home/ubuntu/veenaModal/scripts/validate_modal_endpoint.py:67:    url = f"{ENDPOINT_URL}/v1/tts/metrics"
/home/ubuntu/veenaModal/scripts/validate_modal_endpoint.py:87:    url = f"{ENDPOINT_URL}/v1/tts/generate"
/home/ubuntu/veenaModal/scripts/validate_modal_endpoint.py:115:    url = f"{ENDPOINT_URL}/v1/tts/generate"
/home/ubuntu/veenaModal/scripts/validate_modal_endpoint.py:162:    url = f"{ENDPOINT_URL}/v1/tts/generate"
/home/ubuntu/veenaModal/scripts/validate_modal_endpoint.py:229:    ws_url = f"{ws_url}/v1/tts/ws"
/home/ubuntu/veenaModal/scripts/wer_test_with_emotions.py:129:    API_URL = "http://localhost:8000/v1/tts/generate"
/home/ubuntu/veenaModal/scripts/test_fix.py:11:API_URL = "http://localhost:8000/v1/tts/generate"
/home/ubuntu/veenaModal/scripts/comprehensive_validation.py:176:def generate_tts(text: str, speaker: str = "lipakshi", stream: bool = False, timeout: int = 120) -> Tuple[bytes, Dict]:
/home/ubuntu/veenaModal/scripts/comprehensive_validation.py:183:    url = f"{API_BASE_URL}/v1/tts/generate"
/home/ubuntu/veenaModal/scripts/comprehensive_validation.py:215:    audio_bytes, headers = generate_tts(MULTILINGUAL_TEXT_LARGE, speaker="lipakshi", stream=False, timeout=180)
/home/ubuntu/veenaModal/scripts/comprehensive_validation.py:289:        audio_bytes, headers = generate_tts(text, speaker="lipakshi", stream=False, timeout=120)
/home/ubuntu/veenaModal/scripts/comprehensive_validation.py:325:        audio_bytes, headers = generate_tts(text, speaker=speaker, stream=False, timeout=60)
/home/ubuntu/veenaModal/scripts/comprehensive_validation.py:349:    audio_bytes, headers = generate_tts(test_text, speaker="lipakshi", stream=False, timeout=60)
/home/ubuntu/veenaModal/scripts/comprehensive_validation.py:361:        url = f"{API_BASE_URL}/v1/tts/generate"
/home/ubuntu/veenaModal/scripts/comprehensive_validation.py:407:            audio_bytes, headers = generate_tts(
/home/ubuntu/veenaModal/scripts/comprehensive_validation.py:468:            audio_bytes, headers = generate_tts(text, speaker=speaker, stream=False, timeout=60)
/home/ubuntu/veenaModal/scripts/profile_pipeline.py:44:# === Path setup (same as local_server.py) ===
/home/ubuntu/veenaModal/scripts/profile_pipeline.py:47:for path in [os.path.join(EXTERNAL_DIR, "sparktts"), os.path.join(EXTERNAL_DIR, "AP-BWE"), REPO_ROOT]:
/home/ubuntu/veenaModal/scripts/profile_pipeline.py:653:    from veena3modal.local_server import resolve_model_paths, DEFAULT_LOCAL_MODEL_DIR
/home/ubuntu/veenaModal/scripts/profile_pipeline.py:658:    from veena3modal.services.tts_runtime import initialize_runtime, get_runtime, is_initialized
/home/ubuntu/veenaModal/scripts/profile_pipeline.py:712:    parser.add_argument("--model-path", default=os.path.join(REPO_ROOT, "models", "spark_tts_4speaker"))
/home/ubuntu/veenaModal/scripts/stress_test_local.py:51:GENERATE_PATH = "/v1/tts/generate"
/home/ubuntu/veenaModal/scripts/stress_test_local.py:553:            resp = await client.get(f"{base_url}/v1/tts/health", timeout=10)
/home/ubuntu/veenaModal/scripts/stress_test_optimized_local.py:32:GENERATE_PATH = "/v1/tts/generate"
/home/ubuntu/veenaModal/scripts/stress_test_optimized_local.py:791:            response = await client.get(f"{base_url}/v1/tts/health", timeout=10)
/home/ubuntu/veenaModal/scripts/test_all_features.py:51:            f"{API_BASE_URL}/v1/tts/generate",
/home/ubuntu/veenaModal/scripts/test_all_features.py:88:        f"{API_BASE_URL}/v1/tts/generate",
/home/ubuntu/veenaModal/scripts/test_all_features.py:236:        f"{API_BASE_URL}/v1/tts/generate",
/home/ubuntu/veenaModal/scripts/test_all_features.py:246:        f"{API_BASE_URL}/v1/tts/generate",
/home/ubuntu/veenaModal/scripts/test_all_features.py:257:        f"{API_BASE_URL}/v1/tts/generate",
/home/ubuntu/veenaModal/scripts/test_correct_format.py:12:API_URL = "http://localhost:8000/v1/tts/generate"
/home/ubuntu/veenaModal/scripts/measure_ttfb_detailed.py:14:API_URL = "http://localhost:8000/v1/tts/generate"
/home/ubuntu/veenaModal/scripts/test_original_bug.py:11:API_URL = "http://localhost:8000/v1/tts/generate"
/home/ubuntu/veenaModal/veena3modal/local_server.py:5:1. Sets up PYTHONPATH for vendored deps (sparktts, AP-BWE)
/home/ubuntu/veenaModal/veena3modal/local_server.py:8:4. Serves the FastAPI app via uvicorn
/home/ubuntu/veenaModal/veena3modal/local_server.py:12:    python -m veena3modal.local_server
/home/ubuntu/veenaModal/veena3modal/local_server.py:15:    python -m veena3modal.local_server --model-path /path/to/spark_tts_4speaker
/home/ubuntu/veenaModal/veena3modal/local_server.py:18:    python -m veena3modal.local_server --gpu-memory 0.5 --port 8080
/home/ubuntu/veenaModal/veena3modal/local_server.py:21:    python -m veena3modal.local_server --enable-sr --sr-path /path/to/ap_bwe/16kto48k
/home/ubuntu/veenaModal/veena3modal/local_server.py:24:    python -m veena3modal.local_server --device cpu
/home/ubuntu/veenaModal/veena3modal/local_server.py:43:# Vendored deps: sparktts and AP-BWE live in external/ relative to repo root
/home/ubuntu/veenaModal/veena3modal/local_server.py:47:# sparktts package path: external/sparktts (contains sparktts/ subpackage)
/home/ubuntu/veenaModal/veena3modal/local_server.py:48:SPARKTTS_PATH = os.path.join(EXTERNAL_DIR, "sparktts")
/home/ubuntu/veenaModal/veena3modal/local_server.py:67:DEFAULT_LOCAL_MODEL_DIR = os.path.join(REPO_ROOT, "models", "spark_tts_4speaker")
/home/ubuntu/veenaModal/veena3modal/local_server.py:71:# 2. HuggingFace download (private repo: BayAreaBoys/spark_tts_4speaker)
/home/ubuntu/veenaModal/veena3modal/local_server.py:73:PRIVATE_HF_REPO = "BayAreaBoys/spark_tts_4speaker"
/home/ubuntu/veenaModal/veena3modal/local_server.py:86:    1. Try private repo (BayAreaBoys/spark_tts_4speaker) with HF token
/home/ubuntu/veenaModal/veena3modal/local_server.py:145:        "     modal volume get veena3-models spark_tts_4speaker models/spark_tts_4speaker\n\n"
/home/ubuntu/veenaModal/veena3modal/local_server.py:151:        "     python -m veena3modal.local_server --model-path /path/to/model"
/home/ubuntu/veenaModal/veena3modal/local_server.py:207:    from veena3modal.services.tts_runtime import initialize_runtime
/home/ubuntu/veenaModal/veena3modal/local_server.py:250:    from veena3modal.api.fastapi_app import create_app
/home/ubuntu/veenaModal/veena3modal/local_server.py:251:    return create_app()
/home/ubuntu/veenaModal/veena3modal/local_server.py:261:  python -m veena3modal.local_server                          # Auto-download model, serve on :8000
/home/ubuntu/veenaModal/veena3modal/local_server.py:262:  python -m veena3modal.local_server --port 8080              # Custom port
/home/ubuntu/veenaModal/veena3modal/local_server.py:263:  python -m veena3modal.local_server --model-path ./my_model  # Use local model
/home/ubuntu/veenaModal/veena3modal/local_server.py:264:  python -m veena3modal.local_server --gpu-memory 0.5         # Limit GPU memory
/home/ubuntu/veenaModal/veena3modal/local_server.py:265:  python -m veena3modal.local_server --workers 2              # Multiple workers (careful: each loads model)
/home/ubuntu/veenaModal/veena3modal/local_server.py:350:        help="Number of uvicorn workers (default: 1, each loads full model)",
/home/ubuntu/veenaModal/veena3modal/local_server.py:390:    5. Run uvicorn
/home/ubuntu/veenaModal/veena3modal/local_server.py:436:    # Run uvicorn
/home/ubuntu/veenaModal/veena3modal/local_server.py:437:    # NOTE: We use the factory string so uvicorn can find the app.
/home/ubuntu/veenaModal/veena3modal/local_server.py:438:    # With --reload, uvicorn reimports, but the runtime singleton persists in memory.
/home/ubuntu/veenaModal/veena3modal/local_server.py:439:    import uvicorn
/home/ubuntu/veenaModal/veena3modal/local_server.py:445:    logger.info(f"  Health: http://{args.host}:{args.port}/v1/tts/health")
/home/ubuntu/veenaModal/veena3modal/local_server.py:446:    logger.info(f"  Generate: POST http://{args.host}:{args.port}/v1/tts/generate")
/home/ubuntu/veenaModal/veena3modal/local_server.py:447:    logger.info(f"  Metrics: http://{args.host}:{args.port}/v1/tts/metrics")
/home/ubuntu/veenaModal/veena3modal/local_server.py:451:    uvicorn.run(
/home/ubuntu/veenaModal/veena3modal/local_server.py:452:        "veena3modal.local_server:create_local_app",
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:130:        os.environ.get('MODEL_PATH', '/models/spark_tts_4speaker')
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:228:            model_version = "spark-tts"
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:425:            "tts_runtime_nonstream_start",
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:521:                "tts_runtime_nonstream_complete",
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:526:                "tts_runtime_nonstream_inflight",
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:652:                "tts_runtime_chunking_start",
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:779:            logger.info("tts_runtime_chunking_complete", extra=metrics)
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:873:            "tts_runtime_stream_start",
/home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py:976:                "tts_runtime_stream_end",
/home/ubuntu/veenaModal/veena3modal/services/sentence_store.py:21:TABLE_NAME = "tts_requests"
/home/ubuntu/veenaModal/veena3modal/shared/logging.py:188:tts_logger = get_logger("veena3modal.tts")
/home/ubuntu/veenaModal/veena3modal/shared/logging.py:201:        tts_logger,
/home/ubuntu/veenaModal/veena3modal/shared/logging.py:220:        tts_logger,
/home/ubuntu/veenaModal/veena3modal/shared/logging.py:240:        tts_logger,
/home/ubuntu/veenaModal/veena3modal/shared/logging.py:261:        tts_logger,
/home/ubuntu/veenaModal/veena3modal/core/bicodec_decoder.py:14:# Ensure `sparktts` (vendored under external/) is importable in local/dev runs.
/home/ubuntu/veenaModal/veena3modal/core/bicodec_decoder.py:15:# In Modal, PYTHONPATH already includes `/root/external/sparktts`.
/home/ubuntu/veenaModal/veena3modal/core/bicodec_decoder.py:17:    from sparktts.models.audio_tokenizer import BiCodecTokenizer
/home/ubuntu/veenaModal/veena3modal/core/bicodec_decoder.py:20:    _sparktts_path = None
/home/ubuntu/veenaModal/veena3modal/core/bicodec_decoder.py:22:        _candidate = _p / "external" / "sparktts"
/home/ubuntu/veenaModal/veena3modal/core/bicodec_decoder.py:24:            _sparktts_path = str(_candidate)
/home/ubuntu/veenaModal/veena3modal/core/bicodec_decoder.py:26:    if _sparktts_path and _sparktts_path not in sys.path:
/home/ubuntu/veenaModal/veena3modal/core/bicodec_decoder.py:27:        sys.path.insert(0, _sparktts_path)
/home/ubuntu/veenaModal/veena3modal/core/bicodec_decoder.py:28:    from sparktts.models.audio_tokenizer import BiCodecTokenizer
/home/ubuntu/veenaModal/veena3modal/core/bicodec_decoder.py:234:        From sparktts/models/bicodec.py line 184-186:
/home/ubuntu/veenaModal/veena3modal/shared/metrics.py:72:        'veena3_tts_requests_total',
/home/ubuntu/veenaModal/veena3modal/shared/metrics.py:79:        'veena3_tts_requests_completed_total',
/home/ubuntu/veenaModal/veena3modal/shared/metrics.py:86:        'veena3_tts_requests_failed_total',
/home/ubuntu/veenaModal/veena3modal/shared/metrics.py:94:        'veena3_tts_ttfb_seconds',
/home/ubuntu/veenaModal/veena3modal/shared/metrics.py:102:        'veena3_tts_rtf',
/home/ubuntu/veenaModal/veena3modal/shared/metrics.py:110:        'veena3_tts_audio_duration_seconds',
/home/ubuntu/veenaModal/veena3modal/shared/metrics.py:118:        'veena3_tts_chunks_sent',
/home/ubuntu/veenaModal/veena3modal/shared/metrics.py:127:        'veena3_tts_model_load_seconds',
/home/ubuntu/veenaModal/veena3modal/shared/metrics.py:134:        'veena3_tts_model_loaded',
/home/ubuntu/veenaModal/veena3modal/__main__.py:1:"""Allow running as: python -m veena3modal (shortcut for local_server)."""
/home/ubuntu/veenaModal/veena3modal/__main__.py:2:from veena3modal.local_server import main
/home/ubuntu/veenaModal/external/sparktts/utils/token_parser.py:3:    "tts": "<|task_tts|>",
/home/ubuntu/veenaModal/external/sparktts/utils/token_parser.py:9:    "controllable_tts": "<|task_controllable_tts|>",
/home/ubuntu/veenaModal/external/sparktts/utils/token_parser.py:10:    "prompt_tts": "<|task_prompt_tts|>",
/home/ubuntu/veenaModal/external/sparktts/utils/token_parser.py:165:    tasks = ["tts", "tts", "understand", "controllable_tts", "prompt_tts"]
/home/ubuntu/veenaModal/external/sparktts/models/audio_tokenizer.py:24:from sparktts.utils.file import load_config
/home/ubuntu/veenaModal/external/sparktts/models/audio_tokenizer.py:25:from sparktts.utils.audio import load_audio
/home/ubuntu/veenaModal/external/sparktts/models/audio_tokenizer.py:26:from sparktts.models.bicodec import BiCodec
/home/ubuntu/veenaModal/external/sparktts/models/bicodec.py:23:from sparktts.utils.file import load_config
/home/ubuntu/veenaModal/external/sparktts/models/bicodec.py:24:from sparktts.modules.speaker.speaker_encoder import SpeakerEncoder
/home/ubuntu/veenaModal/external/sparktts/models/bicodec.py:25:from sparktts.modules.encoder_decoder.feat_encoder import Encoder
/home/ubuntu/veenaModal/external/sparktts/models/bicodec.py:26:from sparktts.modules.encoder_decoder.feat_decoder import Decoder
/home/ubuntu/veenaModal/external/sparktts/models/bicodec.py:27:from sparktts.modules.encoder_decoder.wave_generator import WaveGenerator
/home/ubuntu/veenaModal/external/sparktts/models/bicodec.py:28:from sparktts.modules.vq.factorized_vector_quantize import FactorizedVectorQuantize
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:4:Phase 1: expose `/v1/tts/generate` and `/v1/tts/health` while reusing existing
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:218:def create_app():
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:236:    @app.get("/v1/tts/health")
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:237:    async def tts_health():
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:249:        from veena3modal.services import tts_runtime
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:250:        model_loaded = tts_runtime.is_initialized()
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:253:        runtime = tts_runtime.get_runtime()
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:290:    @app.get("/v1/tts/metrics")
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:291:    async def tts_metrics():
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:302:    @app.post("/v1/tts/generate")
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:303:    async def tts_generate(request: Request):
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:311:        from veena3modal.services import tts_runtime
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:392:        if not tts_runtime.is_initialized():
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:446:                audio_bytes, metrics = await tts_runtime.generate_speech_chunked(
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:460:                audio_bytes, metrics = await tts_runtime.generate_speech(
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:492:            runtime = tts_runtime.get_runtime()
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:642:        from veena3modal.services import tts_runtime
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:645:        runtime = tts_runtime.get_runtime()
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:683:                async for audio_chunk, metrics in tts_runtime.generate_speech_streaming(
/home/ubuntu/veenaModal/veena3modal/api/fastapi_app.py:802:        logger.info("WebSocket support enabled at /v1/tts/ws")
/home/ubuntu/veenaModal/external/sparktts/cli/SparkTTS.py:22:from sparktts.utils.file import load_config
/home/ubuntu/veenaModal/external/sparktts/cli/SparkTTS.py:23:from sparktts.models.audio_tokenizer import BiCodecTokenizer
/home/ubuntu/veenaModal/external/sparktts/cli/SparkTTS.py:24:from sparktts.utils.token_parser import LEVELS_MAP, GENDER_MAP, TASK_TOKEN_MAP
/home/ubuntu/veenaModal/external/sparktts/cli/SparkTTS.py:84:                TASK_TOKEN_MAP["tts"],
/home/ubuntu/veenaModal/external/sparktts/cli/SparkTTS.py:97:                TASK_TOKEN_MAP["tts"],
/home/ubuntu/veenaModal/external/sparktts/cli/SparkTTS.py:145:        control_tts_inputs = [
/home/ubuntu/veenaModal/external/sparktts/cli/SparkTTS.py:146:            TASK_TOKEN_MAP["controllable_tts"],
/home/ubuntu/veenaModal/external/sparktts/cli/SparkTTS.py:155:        return "".join(control_tts_inputs)
/home/ubuntu/veenaModal/external/sparktts/cli/inference.py:64:def run_tts(args):
/home/ubuntu/veenaModal/external/sparktts/cli/inference.py:116:    run_tts(args)
/home/ubuntu/veenaModal/external/sparktts/sparktts/utils/token_parser.py:3:    "tts": "<|task_tts|>",
/home/ubuntu/veenaModal/external/sparktts/sparktts/utils/token_parser.py:9:    "controllable_tts": "<|task_controllable_tts|>",
/home/ubuntu/veenaModal/external/sparktts/sparktts/utils/token_parser.py:10:    "prompt_tts": "<|task_prompt_tts|>",
/home/ubuntu/veenaModal/external/sparktts/sparktts/utils/token_parser.py:165:    tasks = ["tts", "tts", "understand", "controllable_tts", "prompt_tts"]
/home/ubuntu/veenaModal/veena3modal/processing/long_text_processor.py:132:        This method is used by _stream_chunked_text in tts_runtime.
/home/ubuntu/veenaModal/veena3modal/processing/long_text_processor.py:339:            logger.info("tts_chunked_nonstream_complete", extra=chunked_metrics)
/home/ubuntu/veenaModal/external/sparktts/sparktts/modules/fsq/residual_fsq.py:13:from sparktts.modules.fsq.finite_scalar_quantization import FSQ
/home/ubuntu/veenaModal/veena3modal/processing/prompt_builder.py:5:Format: <|task_controllable_tts|><|star…2427 tokens truncated…ent.get("/v1/tts/health")
/home/ubuntu/veenaModal/veena3modal/tests/unit/test_fastapi_app.py:83:        response = client.get("/v1/tts/health")
/home/ubuntu/veenaModal/veena3modal/tests/unit/test_fastapi_app.py:91:        response = client.get("/v1/tts/health")
/home/ubuntu/veenaModal/veena3modal/tests/unit/test_fastapi_app.py:99:        response = client.get("/v1/tts/health")
/home/ubuntu/veenaModal/veena3modal/tests/unit/test_fastapi_app.py:122:        fastapi_app.set_model_version("spark-tts-v1.2.3")
/home/ubuntu/veenaModal/veena3modal/tests/unit/test_fastapi_app.py:124:        assert fastapi_app.get_model_version() == "spark-tts-v1.2.3"
/home/ubuntu/veenaModal/veena3modal/tests/unit/test_logging.py:62:            "tts_request_received",
/home/ubuntu/veenaModal/veena3modal/tests/unit/test_metrics.py:97:        record_model_load_time(duration_seconds=15.5, model_version="spark_tts_4speaker")
/home/ubuntu/veenaModal/veena3modal/tests/unit/test_metrics.py:103:        set_model_loaded(loaded=True, model_version="spark_tts_4speaker")
/home/ubuntu/veenaModal/veena3modal/tests/unit/test_sentence_store.py:205:            mock_client.table.assert_called_with('tts_requests')
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:52:    """Test /v1/tts/health endpoint against deployed Modal."""
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:56:        url = get_endpoint_url("/v1/tts/health")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:62:        url = get_endpoint_url("/v1/tts/health")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:75:        url = get_endpoint_url("/v1/tts/health")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:84:    """Test /v1/tts/metrics endpoint against deployed Modal."""
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:88:        url = get_endpoint_url("/v1/tts/metrics")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:94:        url = get_endpoint_url("/v1/tts/metrics")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:102:        url = get_endpoint_url("/v1/tts/metrics")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:107:        assert "veena3_tts_" in text or "# HELP" in text
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:112:    """Test /v1/tts/generate endpoint (non-streaming) against deployed Modal."""
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:116:        url = get_endpoint_url("/v1/tts/generate")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:141:        url = get_endpoint_url("/v1/tts/generate")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:164:        url = get_endpoint_url("/v1/tts/generate")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:181:        url = get_endpoint_url("/v1/tts/generate")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:200:    """Test /v1/tts/generate endpoint (streaming) against deployed Modal."""
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:204:        url = get_endpoint_url("/v1/tts/generate")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:226:        url = get_endpoint_url("/v1/tts/generate")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:264:        url = get_endpoint_url("/v1/tts/generate")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:292:        url = get_endpoint_url("/v1/tts/generate")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:337:        url = get_endpoint_url("/v1/tts/generate")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:356:        url = get_endpoint_url("/v1/tts/generate")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:369:        url = get_endpoint_url("/v1/tts/generate")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:392:        url = get_endpoint_url("/v1/tts/generate")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:419:        url = get_endpoint_url("/v1/tts/generate")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:456:        ws_url = f"{ws_url.rstrip('/')}/v1/tts/ws"
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:496:        ws_url = f"{ws_url.rstrip('/')}/v1/tts/ws"
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:526:        ws_url = f"{ws_url.rstrip('/')}/v1/tts/ws"
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_deployed_endpoint.py:616:        response = httpx.get(get_endpoint_url("/v1/tts/health"), timeout=30.0)
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/debug_asr_issue.py:21:MODAL_ENDPOINT_URL = os.environ.get("MODAL_ENDPOINT_URL", "https://mayaresearch--veena3-tts-ttsservice-serve.modal.run")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/debug_asr_issue.py:45:def generate_tts(text: str, stream: bool = False, chunking: bool = True) -> Tuple[bytes, dict]:
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/debug_asr_issue.py:47:    url = f"{MODAL_ENDPOINT_URL.rstrip('/')}/v1/tts/generate"
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/debug_asr_issue.py:167:    audio_bytes, headers = generate_tts(text, stream=stream, chunking=chunking)
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/debug_asr_issue.py:263:    audio_bytes, headers = generate_tts(text, stream=False, chunking=True)
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_load.py:11:    export MODAL_ENDPOINT_URL="https://mayaresearch--veena3-tts-ttsservice-serve.modal.run"
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_load.py:28:MODAL_ENDPOINT_URL = os.environ.get("MODAL_ENDPOINT_URL", "https://mayaresearch--veena3-tts-ttsservice-serve.modal.run")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_load.py:146:    url = f"{MODAL_ENDPOINT_URL}/v1/tts/generate"
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_asr_validation.py:15:    export MODAL_ENDPOINT_URL="https://mayaresearch--veena3-tts-ttsservice-serve.modal.run"
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_asr_validation.py:32:MODAL_ENDPOINT_URL = os.environ.get("MODAL_ENDPOINT_URL", "https://mayaresearch--veena3-tts-ttsservice-serve.modal.run")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_asr_validation.py:55:def generate_tts(text: str, speaker: str = "Aarvi", stream: bool = False, timeout: float = 120.0) -> Tuple[bytes, dict]:
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_asr_validation.py:62:    url = get_endpoint_url("/v1/tts/generate")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_asr_validation.py:263:        audio_bytes, headers = generate_tts(text)
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_asr_validation.py:286:            audio_bytes, _ = generate_tts(text, speaker=speaker)
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_asr_validation.py:314:        audio_bytes, headers = generate_tts(text, timeout=180.0)
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_asr_validation.py:352:        audio_bytes, headers = generate_tts(text, stream=False, timeout=300.0)
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_asr_validation.py:391:        audio_bytes, headers = generate_tts(text, stream=False, timeout=300.0)
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_asr_validation.py:441:        audio_non_stream, _ = generate_tts(text, stream=False)
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_asr_validation.py:446:        audio_stream, _ = generate_tts(text, stream=True)
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_asr_validation.py:480:                audio_bytes, _ = generate_tts(text, speaker=speaker)
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_asr_validation.py:524:        audio_bytes, headers = generate_tts(text)
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_speaker_consistency.py:12:    export MODAL_ENDPOINT_URL="https://mayaresearch--veena3-tts-ttsservice-serve.modal.run"
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_speaker_consistency.py:28:MODAL_ENDPOINT_URL = os.environ.get("MODAL_ENDPOINT_URL", "https://mayaresearch--veena3-tts-ttsservice-serve.modal.run")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_speaker_consistency.py:44:def generate_tts(text: str, speaker: str = "Aarvi", stream: bool = False, timeout: float = 180.0) -> bytes:
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_speaker_consistency.py:46:    url = get_endpoint_url("/v1/tts/generate")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_speaker_consistency.py:271:        audio_bytes = generate_tts(LONG_TEXT_FOR_CHUNKS, speaker="Aarvi", stream=False, timeout=300.0)
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_speaker_consistency.py:319:        audio_bytes = generate_tts(LONG_TEXT_FOR_CHUNKS, speaker="Nandini", stream=False, timeout=300.0)
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_speaker_consistency.py:354:            audio_bytes = generate_tts(text, speaker=speaker)
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_speaker_consistency.py:387:                audio_bytes = generate_tts(text, speaker=speaker)
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_speaker_consistency.py:434:            audio_bytes = generate_tts(text, speaker=speaker)
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_speaker_consistency.py:464:        speaker1_audio = generate_tts(text, speaker="Aarvi")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_speaker_consistency.py:465:        speaker2_audio = generate_tts(text, speaker="Nandini")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_speaker_consistency.py:493:        audio_bytes = generate_tts(LONG_TEXT_FOR_CHUNKS, speaker="Mira", stream=False, timeout=600.0)
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_speaker_consistency.py:536:        audio_bytes = generate_tts(text, speaker="Aarvi")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_speaker_consistency.py:549:        audio_bytes = generate_tts(text, speaker="Aarvi")
/home/ubuntu/veenaModal/veena3modal/tests/modal_live/test_speaker_consistency.py:570:        audio_bytes = generate_tts("Hello, this is a test.", speaker="Aarvi")
/home/ubuntu/veenaModal/external/sparktts/modules/fsq/residual_fsq.py:13:from sparktts.modules.fsq.finite_scalar_quantization import FSQ
/home/ubuntu/veenaModal/external/sparktts/modules/encoder_decoder/wave_generator.py:20:from sparktts.modules.blocks.layers import (
/home/ubuntu/veenaModal/external/sparktts/modules/encoder_decoder/feat_decoder.py:22:from sparktts.modules.blocks.vocos import VocosBackbone
/home/ubuntu/veenaModal/external/sparktts/modules/encoder_decoder/feat_decoder.py:23:from sparktts.modules.blocks.samper import SamplingBlock
/home/ubuntu/veenaModal/external/sparktts/modules/encoder_decoder/feat_encoder.py:22:from sparktts.modules.blocks.vocos import VocosBackbone
/home/ubuntu/veenaModal/external/sparktts/modules/encoder_decoder/feat_encoder.py:23:from sparktts.modules.blocks.samper import SamplingBlock
/home/ubuntu/veenaModal/external/sparktts/modules/speaker/speaker_encoder.py:20:from sparktts.modules.fsq.residual_fsq import ResidualFSQ
/home/ubuntu/veenaModal/external/sparktts/modules/speaker/speaker_encoder.py:21:from sparktts.modules.speaker.ecapa_tdnn import ECAPA_TDNN_GLOB_c512
/home/ubuntu/veenaModal/external/sparktts/modules/speaker/speaker_encoder.py:22:from sparktts.modules.speaker.perceiver_encoder import PerceiverResampler
/home/ubuntu/veenaModal/external/sparktts/modules/speaker/ecapa_tdnn.py:25:import sparktts.modules.speaker.pooling_layers as pooling_layers
/home/ubuntu/veenaModal/veena3modal/core/dual_engine.py:69:    To activate, modify tts_runtime.py to use DualEngineRouter instead of
/home/ubuntu/veenaModal/veena3modal/core/dual_engine.py:118:# 1. In tts_runtime.py, replace:
/home/ubuntu/veenaModal/veena3modal/core/constants.py:16:# Model: BayAreaBoys/spark_tts_4speaker (HuggingFace) has 12 speaker tokens
/home/ubuntu/veenaModal/veena3modal/core/constants.py:114:DEFAULT_MODEL_PATH = "BayAreaBoys/spark_tts_4speaker"
/home/ubuntu/veenaModal/veena3modal/core/constants.py:119:BICODEC_TOKENIZER_PATH = os.environ.get('MODEL_PATH', os.environ.get('SPARK_TTS_MODEL_PATH', '/models/spark_tts_4speaker'))
/home/ubuntu/veenaModal/veena3modal/core/model_loader.py:28:    Model: BayAreaBoys/spark_tts_4speaker
/home/ubuntu/veenaModal/veena3modal/api/headers.py:38:def build_tts_response_headers(
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:377:                    "tts_stream_llm_batch",
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:483:                                    "tts_stream_decode_batch",
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:582:            logger.info("tts_stream_indic_complete", extra=request_metrics)
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:733:                    "tts_stream_llm_batch",
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:819:                                "tts_stream_decode_batch",
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:872:                        "tts_stream_decode_batch",
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:944:        logger.info("tts_stream_first_chunk_complete", extra=request_metrics)
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:1102:                    "tts_stream_llm_batch",
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:1182:                                "tts_stream_decode_batch",
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:1235:                                "tts_stream_decode_batch",
/home/ubuntu/veenaModal/veena3modal/core/streaming_pipeline.py:1304:        logger.info("tts_stream_continuation_complete", extra=request_metrics)
/home/ubuntu/veenaModal/veena3modal/api/schemas.py:24:# Model: BayAreaBoys/spark_tts_4speaker (HuggingFace) has 12 speaker tokens
/home/ubuntu/veenaModal/veena3modal/api/schemas.py:156:    Request schema for /v1/tts/generate.
/home/ubuntu/veenaModal/veena3modal/api/schemas.py:375:    """Response metadata for non-streaming /v1/tts/generate."""
/home/ubuntu/veenaModal/veena3modal/api/schemas.py:412:    """Response for /v1/tts/health endpoint."""
/home/ubuntu/veenaModal/veena3modal/core/pipeline.py:175:                    "tts_llm_batch",
/home/ubuntu/veenaModal/veena3modal/core/pipeline.py:192:                    "tts_llm_no_output",
/home/ubuntu/veenaModal/veena3modal/core/pipeline.py:218:                    "tts_bicodec_parse_failed",
/home/ubuntu/veenaModal/veena3modal/core/pipeline.py:272:                logger.error("tts_decode_failed", extra={"speaker": speaker, "request_id": request_id})
/home/ubuntu/veenaModal/veena3modal/core/pipeline.py:312:            logger.info("tts_llm_complete", extra=timing_metrics)
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:10:1. Client connects to /v1/tts/ws
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:211:async def handle_websocket_tts(websocket, api_key: Optional[str] = None):
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:225:    from veena3modal.services import tts_runtime
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:325:        if not tts_runtime.is_initialized():
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:334:        runtime = tts_runtime.get_runtime()
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:388:            async for audio_chunk, metrics in tts_runtime.generate_speech_streaming(
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:530:    Call this from create_app() to enable WebSocket support.
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:537:    @app.websocket("/v1/tts/ws")
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:538:    async def websocket_tts(
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:546:        ws://host/v1/tts/ws?api_key=your-key
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:562:        await handle_websocket_tts(websocket, api_key)
/home/ubuntu/veenaModal/veena3modal/api/websocket_handler.py:564:    logger.info("WebSocket route /v1/tts/ws registered")
/home/ubuntu/veenaModal/external/sparktts/sparktts/modules/speaker/ecapa_tdnn.py:25:import sparktts.modules.speaker.pooling_layers as pooling_layers
/home/ubuntu/veenaModal/veena3modal/app.py:18:    modal run veena3modal/app.py::tts_api
/home/ubuntu/veenaModal/veena3modal/app.py:47:        "uvicorn[standard]>=0.23.0",
/home/ubuntu/veenaModal/veena3modal/app.py:64:        # SparkTTS dependencies (from external/sparktts/requirements.txt)
/home/ubuntu/veenaModal/veena3modal/app.py:81:        # sparktts is at /root/external/sparktts, AP-BWE at /root/external/AP-BWE
/home/ubuntu/veenaModal/veena3modal/app.py:82:        "PYTHONPATH": "/root/external/sparktts:/root/external/AP-BWE:/root",
/home/ubuntu/veenaModal/veena3modal/app.py:85:    # Add sparktts package - create proper structure by copying files
/home/ubuntu/veenaModal/veena3modal/app.py:88:        # Create sparktts package directory
/home/ubuntu/veenaModal/veena3modal/app.py:89:        "mkdir -p /root/external/sparktts/sparktts/models",
/home/ubuntu/veenaModal/veena3modal/app.py:90:        "mkdir -p /root/external/sparktts/sparktts/utils",
/home/ubuntu/veenaModal/veena3modal/app.py:93:        local_path=os.path.join(REPO_ROOT, "external", "sparktts", "sparktts"),
/home/ubuntu/veenaModal/veena3modal/app.py:94:        remote_path="/root/external/sparktts/sparktts",
/home/ubuntu/veenaModal/veena3modal/app.py:98:        local_path=os.path.join(REPO_ROOT, "external", "sparktts", "models"),
/home/ubuntu/veenaModal/veena3modal/app.py:99:        remote_path="/root/external/sparktts/sparktts/models",  # Put models inside sparktts package
/home/ubuntu/veenaModal/veena3modal/app.py:103:        local_path=os.path.join(REPO_ROOT, "external", "sparktts", "utils"),
/home/ubuntu/veenaModal/veena3modal/app.py:104:        remote_path="/root/external/sparktts/sparktts/utils",  # Put utils inside sparktts package
/home/ubuntu/veenaModal/veena3modal/app.py:133:    name="veena3-tts",
/home/ubuntu/veenaModal/veena3modal/app.py:209:            "/models/spark_tts_4speaker"
/home/ubuntu/veenaModal/veena3modal/app.py:223:            from veena3modal.services.tts_runtime import initialize_runtime
/home/ubuntu/veenaModal/veena3modal/app.py:246:        from veena3modal.api.fastapi_app import create_app
/home/ubuntu/veenaModal/veena3modal/app.py:247:        return create_app()
/home/ubuntu/veenaModal/veena3modal/app.py:267:def tts_api():
/home/ubuntu/veenaModal/veena3modal/app.py:274:    from veena3modal.api.fastapi_app import create_app
/home/ubuntu/veenaModal/veena3modal/app.py:275:    return create_app()
/home/ubuntu/veenaModal/veena3modal/app.py:289:        "service": "veena3-tts",
/home/ubuntu/veenaModal/veena3modal/app.py:320:        "/root/external/sparktts",
/home/ubuntu/veenaModal/veena3modal/app.py:321:        "/root/external/sparktts/sparktts",
/home/ubuntu/veenaModal/veena3modal/app.py:322:        "/root/external/sparktts/sparktts/models",
/home/ubuntu/veenaModal/veena3modal/app.py:339:        "sparktts",
/home/ubuntu/veenaModal/veena3modal/app.py:340:        "sparktts.models",
/home/ubuntu/veenaModal/veena3modal/app.py:341:        "sparktts.models.audio_tokenizer",


sed -n '1,260p' /home/ubuntu/veenaModal/veena3modal/local_server.py


Output:
Chunk ID: 95c47a
Wall time: 0.0509 seconds
Process exited with code 0
Original token count: 2380
Output:
"""
Local entry point for Veena3 TTS - runs the same FastAPI app without Modal.

Replicates what Modal's @modal.enter + @modal.asgi_app does:
1. Sets up PYTHONPATH for vendored deps (sparktts, AP-BWE)
2. Downloads model weights from HuggingFace if not present
3. Initializes TTS runtime (vLLM engine, BiCodec decoder, pipelines)
4. Serves the FastAPI app via uvicorn

Usage:
    # Basic (auto-downloads model, uses defaults)
    python -m veena3modal.local_server

    # Custom model path (skip download)
    python -m veena3modal.local_server --model-path /path/to/spark_tts_4speaker

    # Custom GPU memory + port
    python -m veena3modal.local_server --gpu-memory 0.5 --port 8080

    # With super-resolution (48kHz output)
    python -m veena3modal.local_server --enable-sr --sr-path /path/to/ap_bwe/16kto48k

    # CPU-only (no GPU, for testing only - very slow)
    python -m veena3modal.local_server --device cpu

Environment Variables (override defaults):
    MODEL_PATH              - Path to Spark TTS model directory
    HF_TOKEN                - HuggingFace token for private models
    AP_BWE_CHECKPOINT_DIR   - Path to super-resolution checkpoints
    AUTH_BYPASS_MODE        - "true" to disable auth (default for local)
    GPU_MEMORY_UTILIZATION  - vLLM GPU memory fraction (default: 0.25)
"""

from __future__ import annotations

import argparse
import logging
import os
import sys
import time

# === Path Setup (MUST happen before any veena3modal imports) ===
# Vendored deps: sparktts and AP-BWE live in external/ relative to repo root
REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
EXTERNAL_DIR = os.path.join(REPO_ROOT, "external")

# sparktts package path: external/sparktts (contains sparktts/ subpackage)
SPARKTTS_PATH = os.path.join(EXTERNAL_DIR, "sparktts")
# AP-BWE path: external/AP-BWE
AP_BWE_PATH = os.path.join(EXTERNAL_DIR, "AP-BWE")

for path in [SPARKTTS_PATH, AP_BWE_PATH, REPO_ROOT]:
    if path not in sys.path:
        sys.path.insert(0, path)

# Also set PYTHONPATH for subprocesses (e.g., ffmpeg wrappers)
existing_pythonpath = os.environ.get("PYTHONPATH", "")
new_paths = f"{SPARKTTS_PATH}:{AP_BWE_PATH}:{REPO_ROOT}"
if existing_pythonpath:
    os.environ["PYTHONPATH"] = f"{new_paths}:{existing_pythonpath}"
else:
    os.environ["PYTHONPATH"] = new_paths

logger = logging.getLogger("veena3.local")

# Default local model directory (relative to repo)
DEFAULT_LOCAL_MODEL_DIR = os.path.join(REPO_ROOT, "models", "spark_tts_4speaker")

# Model sources (tried in order):
# 1. Local path (--model-path or MODEL_PATH env)
# 2. HuggingFace download (private repo: BayAreaBoys/spark_tts_4speaker)
# 3. Base Spark TTS model (public: SparkAudio/Spark-TTS-0.5B)
PRIVATE_HF_REPO = "BayAreaBoys/spark_tts_4speaker"
PUBLIC_FALLBACK_REPO = "SparkAudio/Spark-TTS-0.5B"

def download_model(
    hf_repo: str = PRIVATE_HF_REPO,
    local_dir: str = DEFAULT_LOCAL_MODEL_DIR,
    hf_token: str | None = None,
) -> str:
    """
    Download Spark TTS model from HuggingFace if not already present.

    Strategy:
    1. Try private repo (BayAreaBoys/spark_tts_4speaker) with HF token
    2. Fall back to public base model (SparkAudio/Spark-TTS-0.5B)
    3. Provide instructions for Modal volume download if both fail

    Returns the resolved local path.
    """
    # Check for any valid marker file (config.json at root, config.yaml, or LLM/config.json)
    marker_files = ["config.json", "config.yaml", "LLM/config.json"]
    if any(os.path.exists(os.path.join(local_dir, m)) for m in marker_files):
        logger.info(f"Model already present at {local_dir}")
        return local_dir

    try:
        from huggingface_hub import snapshot_download
    except ImportError:
        logger.error(
            "huggingface_hub not installed. Install with: pip install huggingface-hub\n"
            "Or download model manually and pass --model-path"
        )
        sys.exit(1)

    os.makedirs(local_dir, exist_ok=True)

    # Try private repo first
    logger.info(f"Attempting download from {hf_repo}...")
    try:
        downloaded_path = snapshot_download(
            repo_id=hf_repo,
            local_dir=local_dir,
            token=hf_token,
            ignore_patterns=["*.bin", "training_args.bin", "optimizer.pt"],
        )
        logger.info(f"Model downloaded to {downloaded_path}")
        return downloaded_path
    except Exception as e:
        logger.warning(f"Private repo download failed: {e}")

    # Try public fallback
    if hf_repo != PUBLIC_FALLBACK_REPO:
        logger.info(f"Trying public base model: {PUBLIC_FALLBACK_REPO}...")
        try:
            downloaded_path = snapshot_download(
                repo_id=PUBLIC_FALLBACK_REPO,
                local_dir=local_dir,
                token=hf_token,
            )
            logger.info(f"Base model downloaded to {downloaded_path}")
            logger.warning(
                "Using public base SparkTTS model (no custom speakers). "
                "For full speaker support, download your fine-tuned model."
            )
            return downloaded_path
        except Exception as e2:
            logger.warning(f"Public model download also failed: {e2}")

    # All downloads failed - provide manual instructions
    logger.error(
        "\nModel download failed. Options:\n"
        "  1. Download from Modal volume:\n"
        "     modal volume get veena3-models spark_tts_4speaker models/spark_tts_4speaker\n\n"
        "  2. Download from HuggingFace (if you have access):\n"
        f"     huggingface-cli download {PRIVATE_HF_REPO} --local-dir {local_dir}\n\n"
        "  3. Use base SparkTTS model:\n"
        f"     huggingface-cli download {PUBLIC_FALLBACK_REPO} --local-dir {local_dir}\n\n"
        "  4. Specify a custom path:\n"
        "     python -m veena3modal.local_server --model-path /path/to/model"
    )
    sys.exit(1)

def resolve_model_paths(model_path: str) -> tuple[str, str]:
    """
    Resolve LLM and BiCodec paths from a Spark TTS model directory.

    Spark TTS model structure (from SparkAudio/Spark-TTS-0.5B):
      model_path/
        LLM/          <- Language model (vLLM loads this)
        BiCodec/      <- Audio tokenizer/decoder
        config.yaml   <- Top-level config

    Fine-tuned models may have LLM files at root (flat structure).
    This function auto-detects both layouts.

    Returns:
        (llm_path, bicodec_path) resolved paths
    """
    # Check for subdirectory layout (SparkAudio/Spark-TTS-0.5B style)
    llm_subdir = os.path.join(model_path, "LLM")
    bicodec_subdir = os.path.join(model_path, "BiCodec")

    if os.path.isdir(llm_subdir) and os.path.exists(os.path.join(llm_subdir, "config.json")):
        llm_path = llm_subdir
    else:
        # Flat layout: LLM files at root
        llm_path = model_path

    # BiCodec path is always the root (it contains BiCodec/ subdir)
    bicodec_path = model_path

    logger.info(f"Resolved model paths:")
    logger.info(f"  LLM (vLLM):    {llm_path}")
    logger.info(f"  BiCodec:       {bicodec_path}")

    return llm_path, bicodec_path

def initialize_local_runtime(
    model_path: str,
    device: str = "cuda",
    gpu_memory_utilization: float = 0.85,
    enable_sr: bool = False,
    sr_checkpoint_dir: str | None = None,
    hf_token: str | None = None,
    num_engines: int = 1,
):
    """
    Initialize TTS runtime for local serving.

    This replaces Modal's @modal.enter lifecycle hook.
    Loads: vLLM engine, BiCodec decoder, prompt builder, pipelines.
    """
    from veena3modal.services.tts_runtime import initialize_runtime

    # Resolve LLM vs BiCodec paths from model directory
    llm_path, bicodec_path = resolve_model_paths(model_path)

    start = time.time()
    logger.info("=" * 60)
    logger.info("Initializing Veena3 TTS Runtime (local)")
    logger.info(f"  Model:       {model_path}")
    logger.info(f"  LLM path:    {llm_path}")
    logger.info(f"  BiCodec:     {bicodec_path}")
    logger.info(f"  Device:      {device}")
    logger.info(f"  GPU Memory:  {gpu_memory_utilization:.0%} (total)")
    logger.info(f"  Engines:     {num_engines}")
    logger.info(f"  SR:          {'enabled' if enable_sr else 'disabled'}")
    logger.info("=" * 60)

    runtime = initialize_runtime(
        model_path=llm_path,
        bicodec_path=bicodec_path,
        sr_checkpoint_dir=sr_checkpoint_dir if enable_sr else None,
        device=device,
        hf_token=hf_token,
        gpu_memory_utilization=gpu_memory_utilization,
        enable_sr=enable_sr,
        num_engines=num_engines,
    )

    elapsed = time.time() - start
    logger.info(f"Runtime initialized in {elapsed:.1f}s")
    logger.info(f"  Model version: {runtime.model_version}")
    logger.info(f"  Streaming: {'available' if runtime.streaming_pipeline else 'unavailable'}")
    logger.info(f"  Super-resolution: {'loaded' if runtime.sr_service and runtime.sr_service.is_loaded else 'disabled'}")

    return runtime

def create_local_app():
    """
    Create the FastAPI app for local serving.

    Same app factory as Modal deployment, but called from local context.
    """
    from veena3modal.api.fastapi_app import create_app
    return create_app()

def parse_args():
    """Parse CLI arguments for local server configuration."""
    parser = argparse.ArgumentParser(
        description="Veena3 TTS Local Server - GPU-accelerated text-to-speech",
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog="""
Examples:


sed -n '260,520p' /home/ubuntu/veenaModal/veena3modal/local_server.py


Output:
Chunk ID: b6a625
Wall time: 0.0510 seconds
Process exited with code 0
Original token count: 1660
Output:
Examples:
  python -m veena3modal.local_server                          # Auto-download model, serve on :8000
  python -m veena3modal.local_server --port 8080              # Custom port
  python -m veena3modal.local_server --model-path ./my_model  # Use local model
  python -m veena3modal.local_server --gpu-memory 0.5         # Limit GPU memory
  python -m veena3modal.local_server --workers 2              # Multiple workers (careful: each loads model)
        """,
    )

    # Model configuration
    model_group = parser.add_argument_group("Model")
    model_group.add_argument(
        "--model-path",
        type=str,
        default=os.environ.get("MODEL_PATH", DEFAULT_LOCAL_MODEL_DIR),
        help=f"Path to Spark TTS model (default: {DEFAULT_LOCAL_MODEL_DIR})",
    )
    model_group.add_argument(
        "--hf-repo",
        type=str,
        default=PRIVATE_HF_REPO,
        help=f"HuggingFace repo to download from (default: {PRIVATE_HF_REPO})",
    )
    model_group.add_argument(
        "--hf-token",
        type=str,
        default=os.environ.get("HF_TOKEN"),
        help="HuggingFace token (default: from HF_TOKEN env var)",
    )
    model_group.add_argument(
        "--skip-download",
        action="store_true",
        help="Don't auto-download model (fail if not found)",
    )

    # GPU configuration
    gpu_group = parser.add_argument_group("GPU")
    gpu_group.add_argument(
        "--device",
        type=str,
        default="cuda",
        choices=["cuda", "cpu"],
        help="Device for inference (default: cuda)",
    )
    gpu_group.add_argument(
        "--gpu-memory",
        type=float,
        default=float(os.environ.get("GPU_MEMORY_UTILIZATION", "0.25")),
        help="vLLM GPU memory utilization fraction (default: 0.25)",
    )
    gpu_group.add_argument(
        "--num-engines",
        type=int,
        default=int(os.environ.get("NUM_ENGINES", "1")),
        help="Number of vLLM engine instances (default: 1, use 2-3 for multi-engine mode)",
    )

    # Super-resolution
    sr_group = parser.add_argument_group("Super-Resolution")
    sr_group.add_argument(
        "--enable-sr",
        action="store_true",
        default=False,
        help="Enable AP-BWE super-resolution (16kHz -> 48kHz)",
    )
    sr_group.add_argument(
        "--sr-path",
        type=str,
        default=os.environ.get("AP_BWE_CHECKPOINT_DIR"),
        help="Path to AP-BWE checkpoint directory",
    )

    # Server configuration
    server_group = parser.add_argument_group("Server")
    server_group.add_argument(
        "--host",
        type=str,
        default="0.0.0.0",
        help="Bind address (default: 0.0.0.0)",
    )
    server_group.add_argument(
        "--port",
        type=int,
        default=int(os.environ.get("PORT", "8000")),
        help="Port to serve on (default: 8000)",
    )
    server_group.add_argument(
        "--workers",
        type=int,
        default=1,
        help="Number of uvicorn workers (default: 1, each loads full model)",
    )
    server_group.add_argument(
        "--reload",
        action="store_true",
        default=False,
        help="Enable auto-reload for development (incompatible with --workers > 1)",
    )

    # Auth
    auth_group = parser.add_argument_group("Auth")
    auth_group.add_argument(
        "--auth",
        action="store_true",
        default=False,
        help="Enable API key authentication (default: disabled for local)",
    )

    # Logging
    log_group = parser.add_argument_group("Logging")
    log_group.add_argument(
        "--log-level",
        type=str,
        default="INFO",
        choices=["DEBUG", "INFO", "WARNING", "ERROR"],
        help="Log level (default: INFO)",
    )

    return parser.parse_args()

def main():
    """
    Main entry point for local TTS server.

    Lifecycle:
    1. Parse args + configure logging
    2. Download model if needed
    3. Initialize TTS runtime (vLLM engine, decoders, pipelines)
    4. Create FastAPI app
    5. Run uvicorn
    """
    args = parse_args()

    # Configure logging
    logging.basicConfig(
        level=getattr(logging, args.log_level),
        format="%(asctime)s | %(levelname)-8s | %(name)s | %(message)s",
        datefmt="%Y-%m-%d %H:%M:%S",
    )

    # Auth bypass for local development (unless --auth flag is set)
    if not args.auth:
        os.environ["AUTH_BYPASS_MODE"] = "true"
        logger.info("Auth bypass enabled (local mode). Use --auth to require API keys.")
    else:
        os.environ.setdefault("AUTH_BYPASS_MODE", "false")

    # Resolve model path
    # Spark TTS root has config.yaml; LLM subdir has config.json; fine-tuned may have config.json at root
    model_path = args.model_path
    model_exists = any(
        os.path.exists(os.path.join(model_path, marker))
        for marker in ("config.json", "config.yaml", "LLM/config.json")
    )
    if not model_exists:
        if args.skip_download:
            logger.error(f"Model not found at {model_path} and --skip-download is set")
            sys.exit(1)
        model_path = download_model(
            hf_repo=args.hf_repo,
            local_dir=model_path,
            hf_token=args.hf_token,
        )

    # Initialize TTS runtime (this is the expensive step - loads model onto GPU)
    initialize_local_runtime(
        model_path=model_path,
        device=args.device,
        gpu_memory_utilization=args.gpu_memory,
        enable_sr=args.enable_sr,
        sr_checkpoint_dir=args.sr_path,
        hf_token=args.hf_token,
        num_engines=args.num_engines,
    )

    # Run uvicorn
    # NOTE: We use the factory string so uvicorn can find the app.
    # With --reload, uvicorn reimports, but the runtime singleton persists in memory.
    import uvicorn

    logger.info("")
    logger.info("=" * 60)
    logger.info(f"Veena3 TTS Local Server starting")
    logger.info(f"  URL: http://{args.host}:{args.port}")
    logger.info(f"  Health: http://{args.host}:{args.port}/v1/tts/health")
    logger.info(f"  Generate: POST http://{args.host}:{args.port}/v1/tts/generate")
    logger.info(f"  Metrics: http://{args.host}:{args.port}/v1/tts/metrics")
    logger.info(f"  Docs: http://{args.host}:{args.port}/docs")
    logger.info("=" * 60)

    uvicorn.run(
        "veena3modal.local_server:create_local_app",
        factory=True,
        host=args.host,
        port=args.port,
        workers=args.workers,
        reload=args.reload,
        log_level=args.log_level.lower(),
        # Performance: keep-alive for connection reuse under load
        timeout_keep_alive=30,
    )

if __name__ == "__main__":
    main()


source /home/ubuntu/veenaModal/venv/bin/activate && python -c "import torch,sys; import llvmlite; import numba; print('torch',torch.__version__); print('llvmlite',llvmlite.__version__); print('numba',numba.__version__)"


Output:
Chunk ID: 5dfe01
Wall time: 4.3816 seconds
Process exited with code 0
Original token count: 12
Output:
torch 2.9.1+cu128
llvmlite 0.44.0
numba 0.61.2


rg -n "VEENA3_TIMING_LOGS|timing|gpu|llm_batch" /home/ubuntu/veenaModal/veena3modal/services/tts_runtime.py /home/ubuntu/veenaModal/veena3modal/core -g'*.py'