|
| 1 | +# PronunciationClient Class |
| 2 | + |
| 3 | +## Defenition |
| 4 | + |
| 5 | +Client for accessing Reverso text-to-speech feature |
| 6 | + |
| 7 | +```csharp |
| 8 | +public class PronunciationClient : IPronunciationClient |
| 9 | +``` |
| 10 | + |
| 11 | +Namespace: ReversoAPI |
| 12 | + |
| 13 | +Inheritance: Object -> PronunciationClient |
| 14 | + |
| 15 | +Implements: IPronunciationClient |
| 16 | + |
| 17 | +## Remarks |
| 18 | + |
| 19 | +This class provides access to text-to-speech conversion. Based on site API. |
| 20 | + |
| 21 | +## Instantiate a ReversoClient |
| 22 | + |
| 23 | +The client is created together with the parent ReversoClient and is also delete together. |
| 24 | + |
| 25 | +```csharp |
| 26 | +using var reverso = new ReversoClient(); |
| 27 | +var reversoPronunciation = reverso.Pronunciation; |
| 28 | +``` |
| 29 | + |
| 30 | +## Methods |
| 31 | + |
| 32 | +## GetAsync(string text, Language language, int speed = 100, CancellationToken cancellationToken = default); Method |
| 33 | + |
| 34 | +## Defenition |
| 35 | + |
| 36 | +Returns a stream with a voiceover of the text. |
| 37 | + |
| 38 | +```csharp |
| 39 | +Task<Stream> GetAsync(string text, Language language, int speed = 100, CancellationToken cancellationToken = default) |
| 40 | +``` |
| 41 | +### Parameters |
| 42 | + |
| 43 | +`text` string |
| 44 | + |
| 45 | +Text containing a text. |
| 46 | + |
| 47 | +`language` Language |
| 48 | + |
| 49 | +Enum containing the source language. |
| 50 | + |
| 51 | +`speed` Int32 |
| 52 | + |
| 53 | +Pronunciation rate |
| 54 | + |
| 55 | +`cancellationToken` CancellationToken |
| 56 | + |
| 57 | +The token to monitor for cancellation requests. The default value is None. |
| 58 | + |
| 59 | +### Returns |
| 60 | + |
| 61 | +`Task<Stream>` |
| 62 | + |
| 63 | +The task representing the asynchronous reading operation. The value of its Result property contains the response from Reverso, which contains stream with a voiceover of the text. |
| 64 | + |
| 65 | +### Remarks |
| 66 | + |
| 67 | +The GetAsync method is based on site API. |
| 68 | + |
| 69 | +### Exceptions |
| 70 | + |
| 71 | +`ArgumentException` |
| 72 | + |
| 73 | +The input text is considered invalid if it is null or empty or exceeds the allowed range limit of text or speed. |
| 74 | + |
| 75 | +`NotSupportedException` |
| 76 | + |
| 77 | +The language input is not supported by Reverso.net. |
| 78 | + |
| 79 | +## Examples |
| 80 | + |
| 81 | +```csharp |
| 82 | +using ReversoAPI; |
| 83 | +using System; |
| 84 | +using System.IO; |
| 85 | +using System.Threading.Tasks; |
| 86 | + |
| 87 | +class Program |
| 88 | +{ |
| 89 | + static async Task Main() |
| 90 | + { |
| 91 | + var text = "run"; |
| 92 | + var source = Language.English; |
| 93 | + |
| 94 | + using var reverso = new ReversoClient(); |
| 95 | + var pronunciationStream = await reverso.Pronunciation.GetAsync(text, source); |
| 96 | + |
| 97 | + if (pronunciationStream is null) |
| 98 | + { |
| 99 | + Console.WriteLine("Failed to get pronunciation"); |
| 100 | + return; |
| 101 | + } |
| 102 | + |
| 103 | + using (var fileStream = File.Create(Environment.GetFolderPath(Environment.SpecialFolder.Desktop))) |
| 104 | + { |
| 105 | + pronunciationStream!.CopyTo(fileStream); |
| 106 | + } |
| 107 | + } |
| 108 | +} |
| 109 | +``` |
| 110 | + |
0 commit comments