Some checks failed
CI Pipeline / Code Quality & Typecheck (push) Waiting to run
CI Pipeline / Test Suite (macos-latest) (push) Blocked by required conditions
CI Pipeline / Test Suite (ubuntu-latest) (push) Blocked by required conditions
CI Pipeline / Test Suite (windows-latest) (push) Blocked by required conditions
CI Pipeline / Build Validation (admin) (push) Blocked by required conditions
CI Pipeline / Build Validation (desktop) (push) Blocked by required conditions
Deploy Landing Page / deploy (push) Blocked by required conditions
Deploy Landing Page / build (push) Waiting to run
Release & Packaging Pipeline / Build & Publish Admin Docker Image (push) Failing after 8s
Release & Code Signing CA Pipeline / build-and-sign-windows (push) Failing after 1m51s
Build macOS / Build & Package (macOS) (push) Failing after 4s
Build macOS / Build & Package (macOS)-1 (push) Failing after 5s
Release & Code Signing CA Pipeline / build-and-sign-macos (push) Failing after 3s
Release & Packaging Pipeline / Package macOS Desktop App (push) Failing after 4s
Release & Packaging Pipeline / Package Windows Desktop App (push) Failing after 2m28s
Release & Packaging Pipeline / Publish Official GitHub Release (push) Has been skipped
109 lines
3.6 KiB
C#
109 lines
3.6 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Security.Claims;
|
|
using System.Threading.Tasks;
|
|
using D3ROVoice.Api.Data;
|
|
using D3ROVoice.Api.Dtos;
|
|
using D3ROVoice.Api.Services;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace D3ROVoice.Api.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class SttController : ControllerBase
|
|
{
|
|
private readonly ISttProxyService _sttService;
|
|
|
|
public SttController(ISttProxyService sttService)
|
|
{
|
|
_sttService = sttService;
|
|
}
|
|
|
|
[HttpPost("transcribe")]
|
|
[Consumes("application/json", "multipart/form-data")]
|
|
public async Task<IActionResult> Transcribe()
|
|
{
|
|
var userIdStr = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
|
var userEmail = User.FindFirstValue(ClaimTypes.Email) ?? "user@d3ro.voice";
|
|
int userId = int.TryParse(userIdStr, out var id) ? id : 1;
|
|
|
|
if (Request.HasFormContentType)
|
|
{
|
|
var form = await Request.ReadFormAsync();
|
|
var file = form.Files.GetFile("file") ?? form.Files.GetFile("audio");
|
|
|
|
if (file == null || file.Length == 0)
|
|
{
|
|
return BadRequest(new { message = "전송할 오디오 파일(file 또는 audio)이 필요합니다." });
|
|
}
|
|
|
|
using var memoryStream = new MemoryStream();
|
|
await file.CopyToAsync(memoryStream);
|
|
var audioBytes = memoryStream.ToArray();
|
|
|
|
var language = form["language"].ToString();
|
|
var prompt = form["prompt"].ToString();
|
|
var model = form["model"].ToString();
|
|
var provider = form["provider"].ToString();
|
|
|
|
var request = new SttTranscribeRequest(
|
|
AudioBase64: null,
|
|
Language: string.IsNullOrWhiteSpace(language) ? "ko" : language,
|
|
InitialPrompt: string.IsNullOrWhiteSpace(prompt) ? null : prompt,
|
|
ModelId: string.IsNullOrWhiteSpace(model) ? null : model,
|
|
Provider: string.IsNullOrWhiteSpace(provider) ? null : provider
|
|
);
|
|
|
|
var result = await _sttService.TranscribeAsync(
|
|
userId,
|
|
userEmail,
|
|
request,
|
|
audioBytes,
|
|
file.ContentType ?? "audio/webm",
|
|
file.FileName ?? "recording.webm"
|
|
);
|
|
|
|
return Ok(result);
|
|
}
|
|
else
|
|
{
|
|
// Read JSON body
|
|
using var reader = new StreamReader(Request.Body);
|
|
var json = await reader.ReadToEndAsync();
|
|
|
|
if (string.IsNullOrWhiteSpace(json))
|
|
{
|
|
return BadRequest(new { message = "요청 본문이 비어있습니다." });
|
|
}
|
|
|
|
var request = System.Text.Json.JsonSerializer.Deserialize<SttTranscribeRequest>(
|
|
json,
|
|
new System.Text.Json.JsonSerializerOptions { PropertyNameCaseInsensitive = true }
|
|
);
|
|
|
|
if (request == null || string.IsNullOrWhiteSpace(request.AudioBase64))
|
|
{
|
|
return BadRequest(new { message = "AudioBase64 데이터가 필요합니다." });
|
|
}
|
|
|
|
var result = await _sttService.TranscribeAsync(userId, userEmail, request);
|
|
return Ok(result);
|
|
}
|
|
}
|
|
|
|
[HttpGet("providers")]
|
|
public async Task<IActionResult> GetActiveProviders()
|
|
{
|
|
var endpoints = await _sttService.GetAllEndpointsAsync();
|
|
return Ok(endpoints);
|
|
}
|
|
|
|
[HttpPost("test")]
|
|
public async Task<IActionResult> TestConnection([FromQuery] int endpointId = 0)
|
|
{
|
|
var result = await _sttService.TestEndpointAsync(endpointId);
|
|
return Ok(result);
|
|
}
|
|
}
|