commit 9ee235160c06c016bb720c6b469d705d5263e426
parent f94ffb47214afb0a837e6044bd4518ba1492ae43
Author: Minerva-Juppiter <ryouturn@gmail.com>
Date: Mon, 14 Aug 2023 10:38:28 +0900
Diffstat:
6 files changed, 85 insertions(+), 12 deletions(-)
diff --git a/A3RTService.cs b/A3RTService.cs
@@ -36,7 +36,7 @@ namespace Aida_chiyo_Talk_app
HttpClient client = new HttpClient();
// リクエストURL
- string uri = $"https://api.a3rt.recruit-tech.co.jp/talk/v1/smalltalk";
+ string uri = $"https://api.a3rt.recruit.co.jp/talk/v1/smalltalk";
// リクエスト本文
var content = new FormUrlEncodedContent(
diff --git a/MainController.cs b/MainController.cs
@@ -10,29 +10,33 @@ namespace Aida_chiyo_Talk_app
{
internal class MainController
{
- public void MainCon()
+ public async Task MainCon()
{
//wakeup
Console.WriteLine("We have woke up.");
Console.WriteLine("Input someting you like.");
+ VoicevoxUtility.EnumerateSpeakers().ToString();
+ /*
//Let's talk
while (true)
{
- Talkcon();
+ await Talkcon();
}
+ */
}
- public void Talkcon()
+ public async Task Talkcon()
{
Inputs inputs = new Inputs();
//string input = inputs.InputConsole();
var output = new Output();
+
TalkAI talkAI = new TalkAI();
- talkAI.TalkAIcon();
+ //talkAI.TalkAIcon();
- talkAI.A3RTcon();
+ await talkAI.A3RTcon();
/*
TalkEngine talkEngine = new TalkEngine();
string answer = talkEngine.CallTalkAPI(input).ToString();
diff --git a/Output.cs b/Output.cs
@@ -10,6 +10,8 @@ namespace Aida_chiyo_Talk_app
{
public void OutputConsole(string output)
{
+ VoiceVox voiceVox = new VoiceVox();
+ voiceVox.VoiceVoxCon(output);
Console.WriteLine(output);
}
}
diff --git a/Program.cs b/Program.cs
@@ -3,4 +3,4 @@ using Aida_chiyo_Talk_app;
MainController mainController = new MainController();
// mainController.MainCon();
-mainController.Talkcon();-
\ No newline at end of file
+await mainController.MainCon();+
\ No newline at end of file
diff --git a/TalkAI.cs b/TalkAI.cs
@@ -70,7 +70,6 @@ namespace Aida_chiyo_Talk_app
}
answer = answer.Replace("</s>", "");
output.OutputConsole(answer);
- voiceVox.VoiceVoxCon(answer);
InputString = inputs.InputConsole();
}
this.ExitCode = process.ExitCode;
@@ -88,15 +87,17 @@ namespace Aida_chiyo_Talk_app
}
- public void A3RTcon()
+ public async Task A3RTcon()
{
A3RTService a3RTService = new A3RTService();
Inputs inputs = new Inputs();
Output output = new Output();
string input = inputs.InputConsole();
+ string A3RTanswer;
while (true)
{
- output.OutputConsole(a3RTService.MakeRequestAsync(input).ToString());
+ A3RTanswer = await a3RTService.MakeRequestAsync(input);
+ output.OutputConsole(A3RTanswer);
input = inputs.InputConsole();
}
}
diff --git a/VoiceVox.cs b/VoiceVox.cs
@@ -1,9 +1,12 @@
-using System;
+using Microsoft.Scripting.Hosting.Shell;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Media;
using System.Net.Http.Headers;
using System.Text;
+using System.Text.Json;
+using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace Aida_chiyo_Talk_app
@@ -62,5 +65,68 @@ namespace Aida_chiyo_Talk_app
player.PlaySync();
//Console.WriteLine("再生完了");
}
+
+ [JsonPropertyName("name")]
+ public string Name { get; set; }
+
+ [JsonPropertyName("id")]
+ public int Id { get; set; }
+ }
+
+ public class SupportedFeatures
+ {
+ [JsonPropertyName("permitted_synthesis_morphing")]
+ public string PermittedSynthesisMorphing { get; set; }
+ }
+
+ public class Speaker
+ {
+ [JsonPropertyName("supported_features")]
+ public SupportedFeatures SupportedFeatures { get; set; }
+
+ [JsonPropertyName("name")]
+ public string Name { get; set; }
+
+ [JsonPropertyName("speaker_uuid")]
+ public string SpeakerUuid { get; set; }
+
+ [JsonPropertyName("styles")]
+ public List<Style> Styles { get; set; }
+
+ [JsonPropertyName("version")]
+ public string Version { get; set; }
+ }
+
+ public static class VoicevoxUtility
+ {
+ const string baseUrl = "http://127.0.0.1:50021/";
+ // localhostだとレスポンスが遅いのアドレス指定
+ private static readonly HttpClient httpClient = new HttpClient();
+
+ public static IEnumerable<Speaker> EnumerateSpeakers()
+ {
+ var jsonStr = GetSpeakersAsJson().Result;
+ var deserialized = JsonSerializer.Deserialize<List<Speaker>>(jsonStr);
+ if (deserialized is null)
+ {
+ yield break;
+ }
+
+ foreach (var speakerInfo in deserialized)
+ {
+ yield return speakerInfo;
+ }
+ }
+
+ private static async Task<string> GetSpeakersAsJson()
+ {
+ using var requestMessage = new HttpRequestMessage(new HttpMethod("GET"), $"{baseUrl}speakers");
+ requestMessage.Headers.TryAddWithoutValidation("accept", "application/json");
+
+ requestMessage.Content = new StringContent("");
+ requestMessage.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/x-www-form-urlencoded");
+ var response = await httpClient.SendAsync(requestMessage);
+ return await response.Content.ReadAsStringAsync();
+ }
}
}