- From the below code user will navigate to the news.google.com.
- Extract everything under span tag.
- Save the extracted text to a string array.
- Data cleansing on the array.
- Transfer the array text to speech engine.
public static void Main(string[] args)
{
IWebDriver driver;
driver = new ChromeDriver(@"C:\Driver\2.41.0\");
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);
driver.Navigate().GoToUrl("https://news.google.com");
IList<IWebElement> elm = driver.FindElements(By.TagName("span"));
string[] a = new string[2000];
int i = 0;
foreach (var item in elm)
{
a[i++] = item.Text.ToString();
}
a = a.Where(x => !string.IsNullOrEmpty(x)).ToArray();
int j = 0;
foreach (var item in a)
{
if (a[j].Length < 30)
{
a[j] = "";
}
j++;
}
a = a.Where(x => !string.IsNullOrEmpty(x)).ToArray();
SpeechSynthesizer synthesizer = new SpeechSynthesizer();
synthesizer.SelectVoiceByHints(VoiceGender.Female, VoiceAge.Senior);
synthesizer.Volume = 100;
synthesizer.Rate = -1;
int k = 1;
foreach (var item in a)
{
synthesizer.Speak(a[k]);
k++;
}
}