示例#1
0
        public static ApiWord.Types.Pronunciation Create(string displayName, string yngping, AudioClip?audioClip = null)
        {
            var word = new ApiWord.Types.Pronunciation
            {
                DisplayName    = displayName,
                Pronunciation_ = yngping,
            };

            if (audioClip != null)
            {
                word.Audio = AudioResources.WithAudioClip(audioClip.BlobLocation);
                return(word);
            }
            if (YngpingTtsUtil.IsPronounceable(yngping))
            {
                word.Audio = AudioResources.WithTtsUrls(yngping);
            }
            return(word);
        }
        public override Task <GenerateSandhiResponse> GenerateSandhi(GenerateSandhiRequest request,
                                                                     ServerCallContext context)
        {
            var results = new List <GenerateSandhiResponse.Types.SandhiResult>();

            foreach (var input in request.Inputs)
            {
                try
                {
                    var inputSyllables = input.ToLowerInvariant().Trim()
                                         .Split()
                                         .Select(syllable => syllable.Trim())
                                         .Where(syllable => syllable.Length > 0)
                                         .ToArray();
                    var outputSyllables = SandhiGenerator.GenerateSandhiSyllables(inputSyllables);
                    var output          = string.Join(" ", outputSyllables);
                    var result          = new GenerateSandhiResponse.Types.SandhiResult
                    {
                        Output = output
                    };
                    if (YngpingTtsUtil.IsPronounceable(output))
                    {
                        result.AudioUrl = "https://api.ydict.net/tts/" + Uri.EscapeDataString(output);
                    }
                    ;
                    results.Add(result);
                }
                catch (Exception)
                {
                    results.Add(new GenerateSandhiResponse.Types.SandhiResult
                    {
                        HasError = true
                    });
                }
            }
            return(Task.FromResult(new GenerateSandhiResponse
            {
                Results = { results }
            }));
        }
示例#3
0
 public void TestIsPronounceable_True(string yngping)
 {
     Assert.True(YngpingTtsUtil.IsPronounceable(yngping));
 }
示例#4
0
 public void TestSyllableToAudio_UnsupportedSyllable_ReturnsEmpty(string yngping)
 {
     Assert.Equal(string.Empty, YngpingTtsUtil.SyllableToAudio(yngping));
 }
示例#5
0
 public void TestSyllableToAudio(string yngping, string expectedFileName)
 {
     Assert.Equal(expectedFileName, YngpingTtsUtil.SyllableToAudio(yngping));
 }