webapi /api/speech
This commit is contained in:
parent
1bc8d41559
commit
4e3557b9e9
@ -1,3 +1,5 @@
|
|||||||
|
using GLMSearch.Tool;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using WebSSE;
|
using WebSSE;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
@ -27,4 +29,42 @@ app.MapControllers();
|
|||||||
//app.MapMcpSse();
|
//app.MapMcpSse();
|
||||||
app.MapMcp();
|
app.MapMcp();
|
||||||
|
|
||||||
|
app.MapPost("/api/speech", ([FromBody] SpeechRequest request) =>
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(request.Input))
|
||||||
|
return Results.BadRequest("Input is required.");
|
||||||
|
if (string.IsNullOrWhiteSpace(request.Voice))
|
||||||
|
request.Voice = "zh-CN-XiaoxiaoNeural";
|
||||||
|
if (string.IsNullOrWhiteSpace(request.Instructions))
|
||||||
|
request.Instructions = "newscast";
|
||||||
|
if (string.IsNullOrWhiteSpace(request.ResponseFormat))
|
||||||
|
request.ResponseFormat = "audio-16khz-32kbitrate-mono-mp3";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var url = Speech2.SpeechGenerate(
|
||||||
|
request.Input,
|
||||||
|
request.Voice,
|
||||||
|
request.Instructions,
|
||||||
|
request.ResponseFormat
|
||||||
|
);
|
||||||
|
if (!string.IsNullOrEmpty(url))
|
||||||
|
{
|
||||||
|
return Results.Ok(new { success = true, url, markdown = $"[µã»÷²¥·ÅÓïÒô]({url})" });
|
||||||
|
}
|
||||||
|
return Results.StatusCode(500);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Results.StatusCode(500);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|
||||||
|
public class SpeechRequest
|
||||||
|
{
|
||||||
|
public string Input { get; set; }
|
||||||
|
public string Voice { get; set; }
|
||||||
|
public string Instructions { get; set; }
|
||||||
|
public string ResponseFormat { get; set; }
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user