Beispiel #1
0
        public async ValueTask <ISpeechResult> TranslateTextAsync(GoogleSpeechRequest request)
        {
            var result = new GoogleSpeechResult();

            var chunks = request.Content.Chunk(30).ToArray();

            var textIndex = 0;

            for (int i = 0; i < chunks.Length; i++)
            {
                if (i > 0)
                {
                    await Task.Delay(60000);
                }

                var tasks = new List <Task>();

                foreach (var chunk in chunks[i])
                {
                    tasks.Add(QueueText(chunk, textIndex, request, result));
                    textIndex++;
                }

                await Task.WhenAll(tasks);
            }

            return(result);
        }
Beispiel #2
0
        private async Task QueueText(string text, int index, GoogleSpeechRequest request, GoogleSpeechResult result)
        {
            var response = await _client.SynthesizeSpeechAsync(
                input : new SynthesisInput
            {
                Text = text
            },
                voice : request.VoiceSelection,
                audioConfig : request.AudioConfig
                );

            result.DigestBytes(index, response.AudioContent);

            if (request.CallBack != null)
            {
                await request.CallBack(text.Length);
            }
        }