Skip to content

EdgeTtsWebSocketServer: Remove broken SQLite/SpeechLock dependency - causing TTS failures #282

Description

@Olbrasoft

Summary

EdgeTtsWebSocketServer is broken because it references non-existent VoiceAssistant.Data.EntityFrameworkCore project with SQLite database. This causes all TTS requests to fail with 0 bytes audio output.

We no longer use SQLite anywhere - the entire system uses PostgreSQL now.

Current Problem

Symptoms

When TTS request hits EdgeTTS-HTTP server (port 5555):

  1. Server tries to check SpeechLockExistsQuery via SQLite
  2. SQLite connection fails (database doesn't exist)
  3. Server continues but WebSocket to Microsoft returns 0 bytes
  4. Circuit breaker trips → fallback to VoiceRSS/PiperTTS (wrong voice)

Error from logs

Microsoft.Data.Sqlite.SqliteException
at VoiceAssistant.Data.EntityFrameworkCore.QueryHandlers.SpeechLockQueryHandlers.SpeechLockExistsQueryHandler.GetResultToHandleAsync
at EdgeTtsWebSocketServer.Services.EdgeTtsService.IsSpeechLockedAsync()

Connected to Microsoft Edge TTS WebSocket
WebSocket closed by server
Total audio data collected: 0 bytes

Root Cause

EdgeTtsWebSocketServer.csproj references:

<ProjectReference Include="..\Data.EntityFrameworkCore\Data.EntityFrameworkCore.csproj" />

This project (VoiceAssistant.Data.EntityFrameworkCore) was the old SQLite-based data layer that no longer exists. The system now uses PostgreSQL via VirtualAssistant.Data.EntityFrameworkCore.

Affected Files

EdgeTtsService.cs

Contains IsSpeechLockedAsync(), ShouldBlockSpeechAsync(), IsCapsLockOn() - all this speech blocking logic needs to be removed.

AssistantSpeechStateService.cs

Uses VoiceAssistantDbContext (the old SQLite one) for tracking assistant speech state. Delete entire file.

Program.cs (line 10)

builder.Services.AddVoiceAssistantData(builder.Configuration);

Registers the old SQLite-based data services.

Required Fix

Remove ALL SpeechLock, CapsLock, and database dependencies completely:

  1. Remove project reference from EdgeTtsWebSocketServer.csproj:

    <!-- DELETE THIS LINE -->
    <ProjectReference Include="..\Data.EntityFrameworkCore\Data.EntityFrameworkCore.csproj" />
  2. Delete AssistantSpeechStateService.cs entirely

  3. In EdgeTtsService.cs remove:

    • IsSpeechLockedAsync() method
    • IsCapsLockOn() method
    • ShouldBlockSpeechAsync() method
    • All calls to these methods
    • _assistantSpeechState field and its usage
    • Constructor parameter AssistantSpeechStateService assistantSpeechState
  4. Update Program.cs:

    • Remove builder.Services.AddVoiceAssistantData(builder.Configuration);
    • Remove builder.Services.AddSingleton<AssistantSpeechStateService>();
  5. Remove unused usings:

    • Olbrasoft.Mediation
    • Olbrasoft.VoiceAssistant.Shared.Data.Queries.SpeechLockQueries
    • Olbrasoft.VoiceAssistant.Data.EntityFrameworkCore
  6. In SpeakAsync() method - remove the speech lock check at the beginning:

    // DELETE THIS BLOCK:
    if (await ShouldBlockSpeechAsync())
    {
        _logger.LogInformation("Speech blocked - skipping TTS for: {Text}", text);
        return (true, string.Empty, false);
    }
  7. In PlayAudioAsync() method - remove:

    • await _assistantSpeechState.StartSpeakingAsync();
    • await _assistantSpeechState.StopSpeakingAsync();
    • The polling loop that checks IsCapsLockOn() during playback

Testing

After fix:

  1. Restart edge-tts-server service: systemctl --user restart edge-tts-server.service
  2. Reset circuit breakers: curl -X POST http://localhost:5055/api/tts/reset-circuit-breaker
  3. Test TTS: curl -X POST http://localhost:5055/api/tts/speak -H "Content-Type: application/json" -d '{"text": "Test"}'
  4. Verify logs show TTS generated by 'EdgeTTS-HTTP' (not VoiceRSS or PiperTTS)

Additional Context

Python edge-tts works fine

edge-tts --voice cs-CZ-AntoninNeural --text "Test" --write-media /tmp/test.mp3
# Creates 11KB file successfully

This proves Microsoft Edge TTS service is working. The problem is our C# server's broken dependencies.

Acceptance Criteria

  • EdgeTtsWebSocketServer has no SQLite/EF Core dependencies
  • No SpeechLockExistsQuery calls anywhere in the project
  • No IsCapsLockOn() method
  • No ShouldBlockSpeechAsync() method
  • AssistantSpeechStateService.cs deleted
  • Server starts without database errors
  • TTS requests return audio (not 0 bytes)
  • EdgeTTS-HTTP becomes primary provider again (not falling back to VoiceRSS)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtts

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions