- AiVoiceRecording 모델 (상태 상수, 접근자) - AiVoiceRecordingService (GCS 업로드, STT, Gemini 분석 파이프라인) - AiVoiceRecordingController (CRUD, 녹음 처리, 상태 폴링) - React 블레이드 뷰 (녹음 UI, 파일 업로드, 목록, 상세 모달) - 라우트 추가 (system/ai-voice-recording) - 메뉴 시더에 AI 음성녹음 항목 추가 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
205 lines
5.4 KiB
PHP
205 lines
5.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\System;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\AiVoiceRecording;
|
|
use App\Services\AiVoiceRecordingService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\View\View;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class AiVoiceRecordingController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly AiVoiceRecordingService $service
|
|
) {}
|
|
|
|
/**
|
|
* React 뷰 반환
|
|
*/
|
|
public function index(Request $request): View|Response
|
|
{
|
|
if ($request->header('HX-Request')) {
|
|
return response('', 200)->header('HX-Redirect', route('system.ai-voice-recording.index'));
|
|
}
|
|
|
|
return view('system.ai-voice-recording.index');
|
|
}
|
|
|
|
/**
|
|
* JSON 목록
|
|
*/
|
|
public function list(Request $request): JsonResponse
|
|
{
|
|
$params = $request->only(['search', 'status', 'per_page']);
|
|
$recordings = $this->service->getList($params);
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => $recordings,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 새 녹음 생성
|
|
*/
|
|
public function store(Request $request): JsonResponse
|
|
{
|
|
$validated = $request->validate([
|
|
'title' => 'nullable|string|max:200',
|
|
]);
|
|
|
|
$recording = $this->service->create($validated);
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'message' => '녹음이 생성되었습니다.',
|
|
'data' => $recording,
|
|
], 201);
|
|
}
|
|
|
|
/**
|
|
* Base64 오디오 업로드 + 처리
|
|
*/
|
|
public function processAudio(Request $request, int $id): JsonResponse
|
|
{
|
|
$recording = AiVoiceRecording::find($id);
|
|
|
|
if (! $recording) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => '녹음을 찾을 수 없습니다.',
|
|
], 404);
|
|
}
|
|
|
|
$validated = $request->validate([
|
|
'audio' => 'required|string',
|
|
'duration' => 'required|integer|min:1',
|
|
]);
|
|
|
|
$result = $this->service->processAudio(
|
|
$recording,
|
|
$validated['audio'],
|
|
$validated['duration']
|
|
);
|
|
|
|
if (! $result['ok']) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => $result['error'] ?? '처리 중 오류가 발생했습니다.',
|
|
], 500);
|
|
}
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'message' => '음성 분석이 완료되었습니다.',
|
|
'data' => $result['recording'],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 파일 업로드 + 처리
|
|
*/
|
|
public function uploadFile(Request $request): JsonResponse
|
|
{
|
|
$validated = $request->validate([
|
|
'audio_file' => 'required|file|mimes:webm,wav,mp3,ogg,m4a,mp4|max:102400',
|
|
'title' => 'nullable|string|max:200',
|
|
]);
|
|
|
|
$recording = $this->service->create([
|
|
'title' => $validated['title'] ?? '업로드된 음성녹음',
|
|
]);
|
|
|
|
$result = $this->service->processUploadedFile(
|
|
$recording,
|
|
$request->file('audio_file')
|
|
);
|
|
|
|
if (! $result['ok']) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => $result['error'] ?? '처리 중 오류가 발생했습니다.',
|
|
], 500);
|
|
}
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'message' => '음성 분석이 완료되었습니다.',
|
|
'data' => $result['recording'],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 상세 조회
|
|
*/
|
|
public function show(int $id): JsonResponse
|
|
{
|
|
$recording = $this->service->getById($id);
|
|
|
|
if (! $recording) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => '녹음을 찾을 수 없습니다.',
|
|
], 404);
|
|
}
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => $recording,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 삭제
|
|
*/
|
|
public function destroy(int $id): JsonResponse
|
|
{
|
|
$recording = AiVoiceRecording::find($id);
|
|
|
|
if (! $recording) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => '녹음을 찾을 수 없습니다.',
|
|
], 404);
|
|
}
|
|
|
|
$this->service->delete($recording);
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'message' => '녹음이 삭제되었습니다.',
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 처리 상태 폴링용
|
|
*/
|
|
public function status(int $id): JsonResponse
|
|
{
|
|
$recording = AiVoiceRecording::find($id);
|
|
|
|
if (! $recording) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => '녹음을 찾을 수 없습니다.',
|
|
], 404);
|
|
}
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => [
|
|
'id' => $recording->id,
|
|
'status' => $recording->status,
|
|
'status_label' => $recording->status_label,
|
|
'is_completed' => $recording->isCompleted(),
|
|
'is_processing' => $recording->isProcessing(),
|
|
'transcript_text' => $recording->transcript_text,
|
|
'analysis_text' => $recording->analysis_text,
|
|
],
|
|
]);
|
|
}
|
|
}
|