complete text2speech in queue service
This commit is contained in:
parent
8d5f28df86
commit
0b32ae4d0f
|
|
@ -128,18 +128,13 @@ public class TwilioVoiceController : TwilioController
|
|||
}
|
||||
else
|
||||
{
|
||||
var textToSpeechService = CompletionProvider.GetTextToSpeech(_services, "openai", "tts-1");
|
||||
var fileService = _services.GetRequiredService<IFileStorageService>();
|
||||
var data = await textToSpeechService.GenerateSpeechFromTextAsync(reply.Content);
|
||||
var fileName = $"reply_{reply.MessageId ?? seqNum.ToString()}.mp3";
|
||||
await fileService.SaveSpeechFileAsync(conversationId, fileName, data);
|
||||
if (reply.ConversationEnd)
|
||||
{
|
||||
response = twilio.HangUp($"twilio/voice/speeches/{conversationId}/{fileName}");
|
||||
response = twilio.HangUp($"twilio/voice/speeches/{conversationId}/{reply.SpeechFileName}");
|
||||
}
|
||||
else
|
||||
{
|
||||
response = twilio.ReturnInstructions($"twilio/voice/speeches/{conversationId}/{fileName}", $"twilio/voice/{conversationId}/receive/{nextSeqNum}?states={states}", true);
|
||||
response = twilio.ReturnInstructions($"twilio/voice/speeches/{conversationId}/{reply.SpeechFileName}", $"twilio/voice/{conversationId}/receive/{nextSeqNum}?states={states}", true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,5 +5,6 @@ namespace BotSharp.Plugin.Twilio.Models
|
|||
public bool ConversationEnd { get; set; }
|
||||
public string Content { get; set; }
|
||||
public string MessageId { get; set; }
|
||||
public string SpeechFileName { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
using BotSharp.Abstraction.Files;
|
||||
using BotSharp.Abstraction.Routing;
|
||||
using BotSharp.Core.Infrastructures;
|
||||
using BotSharp.Plugin.Twilio.Models;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Task = System.Threading.Tasks.Task;
|
||||
|
||||
|
|
@ -94,14 +97,13 @@ namespace BotSharp.Plugin.Twilio.Services
|
|||
async functionExecuted =>
|
||||
{ }
|
||||
);
|
||||
if (reply == null || string.IsNullOrWhiteSpace(reply.Content))
|
||||
{
|
||||
reply = new AssistantMessage()
|
||||
{
|
||||
ConversationEnd = true,
|
||||
Content = "Sorry, something was wrong."
|
||||
};
|
||||
}
|
||||
var textToSpeechService = CompletionProvider.GetTextToSpeech(sp, "openai", "tts-1");
|
||||
var fileService = sp.GetRequiredService<IFileStorageService>();
|
||||
var data = await textToSpeechService.GenerateSpeechFromTextAsync(reply.Content);
|
||||
var fileName = $"reply_{reply.MessageId}.mp3";
|
||||
await fileService.SaveSpeechFileAsync(message.ConversationId, fileName, data);
|
||||
reply.SpeechFileName = fileName;
|
||||
reply.Content = null;
|
||||
await sessionManager.SetAssistantReplyAsync(message.ConversationId, message.SeqNumber, reply);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue