Skip to content

Commit

Permalink
Исправлена ошибка зависания клиента при попытке воспроизведения сообщ…
Browse files Browse the repository at this point in the history
…ения из радио
  • Loading branch information
Canvas123 committed Nov 8, 2023
1 parent 55570cc commit e414917
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 46 deletions.
4 changes: 2 additions & 2 deletions Content.Client/SS220/TTS/TTSSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public override void FrameUpdate(float frameTime)
SoundPathSpecifier soundPath;
if (request is PlayRequestById requestById)
{
tempFilePath = new ResPath($"{requestById.FileIdx}.ogg");
tempFilePath = new ResPath($"{requestById.FileIdx}.wav");
soundPath = new SoundPathSpecifier(Prefix / tempFilePath.Value, requestById.Params);
}
else if (request is PlayRequestByPath requestByPath)
Expand Down Expand Up @@ -224,7 +224,7 @@ private void PlayTTSBytes(byte[] data, EntityUid? sourceUid = null, AudioParams?

var finalParams = audioParams ?? AudioParams.Default;

var filePath = new ResPath($"{_fileIdx}.ogg");
var filePath = new ResPath($"{_fileIdx}.wav");
ContentRoot.AddOrUpdateFile(filePath, data);

// Cache does a funny.
Expand Down
47 changes: 3 additions & 44 deletions Content.Server/SS220/TTS/TTSManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void Initialize()
/// </summary>
/// <param name="speaker">Identifier of speaker</param>
/// <param name="text">SSML formatted text</param>
/// <returns>OGG audio bytes or null if failed</returns>
/// <returns>WAV audio bytes or null if failed</returns>
public async Task<byte[]?> ConvertTextToSpeech(string speaker, string text)
{
WantedCount.Inc();
Expand All @@ -105,13 +105,6 @@ public void Initialize()
}

_sawmill.Debug($"Generate new audio for '{text}' speech by '{speaker}' speaker");

var body = new GenerateVoiceRequest
{
Text = text,
Speaker = speaker,
};

var reqTime = DateTime.UtcNow;
try
{
Expand All @@ -120,7 +113,7 @@ public void Initialize()
var requestUrl = $"{_apiUrl}" + ToQueryString(new NameValueCollection() {
{ "speaker", speaker },
{ "text", text },
{ "ext", "ogg" }});
{ "ext", "wav" }});

var response = await _httpClient.GetAsync(requestUrl, cts.Token);
if (!response.IsSuccessStatusCode)
Expand Down Expand Up @@ -200,7 +193,7 @@ from value in nvc.GetValues(key) ?? Array.Empty<string>()
var reqTime = DateTime.UtcNow;
try
{
var outputFilename = Path.GetTempPath() + Guid.NewGuid() + ".ogg";
var outputFilename = Path.GetTempPath() + Guid.NewGuid() + ".wav";
await FFMpegArguments
.FromPipeInput(new StreamPipeSource(new MemoryStream(soundData)))
.OutputToFile(outputFilename, true, options =>
Expand Down Expand Up @@ -316,38 +309,4 @@ public CrusherFilterArgument(

public string Value => string.Join(":", _arguments.Select<KeyValuePair<string, string>, string>(pair => pair.Key + "=" + pair.Value));
}

private struct GenerateVoiceRequest
{
public GenerateVoiceRequest()
{
}

[JsonPropertyName("speaker")]
public string Speaker { get; set; } = "";

[JsonPropertyName("text")]
public string Text { get; set; } = "";

[JsonPropertyName("ext")]
public string Extension { get; } = "ogg";
}

private struct GenerateVoiceResponse
{
[JsonPropertyName("results")]
// ReSharper disable once CollectionNeverUpdated.Local
// ReSharper disable once UnusedAutoPropertyAccessor.Local
public List<VoiceResult> Results { get; set; }

[JsonPropertyName("original_sha1")]
public string Hash { get; set; }
}

private struct VoiceResult
{
[JsonPropertyName("audio")]
// ReSharper disable once UnusedAutoPropertyAccessor.Local
public string Audio { get; set; }
}
}

1 comment on commit e414917

@VladIsLove-e
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.