Skip to content

complete text2speech in queue service #607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,13 @@ public async Task<TwiMLResult> ReplyCallerMessage([FromRoute] string conversatio
}
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);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ public class AssistantMessage
public bool ConversationEnd { get; set; }
public string Content { get; set; }
public string MessageId { get; set; }
public string SpeechFileName { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -94,14 +97,13 @@ private async Task ProcessUserMessageAsync(CallerMessage message)
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);
}
}
Expand Down