29 lines
819 B
PHP
29 lines
819 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Services\SpeechService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
/**
|
|
* Schneller TTS-Endpoint: Browser POSTet kurzen Text, bekommt audio_url zurück.
|
|
* Wird vom HUD für Status-Ankündigungen genutzt ("Ich suche...", "X gefunden")
|
|
* damit alle Sprachausgaben über Piper Thorsten gehen, nicht via Browser-API.
|
|
*/
|
|
class FoxTtsController
|
|
{
|
|
public function __invoke(Request $request, SpeechService $speech): JsonResponse
|
|
{
|
|
$text = trim((string) $request->input('text', ''));
|
|
|
|
if ($text === '' || mb_strlen($text) > 500) {
|
|
return response()->json(['audio_url' => null, 'error' => 'invalid'], 422);
|
|
}
|
|
|
|
$url = $speech->speak($text);
|
|
|
|
return response()->json(['audio_url' => $url]);
|
|
}
|
|
}
|