I am using freetts library to automate the voice search. But my speakUtil.java is failing and giving error : "FAILED CONFIGURATION: @BeforeClass setup java.lang.Error: Unable to load voice directory. java.lang.ClassNotFoundException: com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory"
I have searched multiple threads related to this but they all tell to add the freetts jar files in lib folder in netbeans, but nothing related to eclipse which I am using.
This is my speakUtil.java class:
public class speakUtil {
static com.sun.speech.freetts.Voice systemVoice = null;
public static void allocate(){
System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
systemVoice = VoiceManager.getInstance().getVoice("kevin16");
systemVoice.allocate();
}
public static void speak(String text){
systemVoice.speak(text);
}
public static void deallocate(){
systemVoice.deallocate();
}
}
This is my selenium test
public class voiceSearchTest {
@BeforeClass
public void setup(){
speakUtil.allocate(); //activating speakUtil before test runs
}
@Test(dataProvider = "voiceSearch")
public void voiceSearch(String searchText) throws InterruptedException {
//code for dealing with Allow mic popup
HashMap<String, Integer> conentSettings = new HashMap<String, Integer>();
HashMap<String, Object> profile = new HashMap<String, Object>();
HashMap<String, Object> prefs = new HashMap<String, Object>();
conentSettings.put("media_stream", 1);
profile.put("managed_default_content_settings", conentSettings);
prefs.put("profile", profile);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
//calling chromedriver
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
driver.get("https://example.com/");
driver.manage().window().maximize();
Thread.sleep(5000);
//creating object to call voice search
pageobjects.voiceSearch voicesearch = new
pageobjects.voiceSearch(driver);
voicesearch.searchClick(); //clicking on search icon
voicesearch.voiceClick(); //clicking on voice search icon
speakUtil.speak(searchText); //speaking text from dataprovider
voicesearch.startListening(); //listening to voice
voicesearch.startListening();
voicesearch.getVoiceSearchText(); //getting spoken voice to validate if same words are being entered as the one spoken.
}
@DataProvider(name = "voiceSearch")
public Object[][] voiceSearch2(){
return new Object[][] {
{"Good Boy"},
};
}
@AfterClass
public void deallocate(){
speakUtil.deallocate(); //deallocating speakUtil.java
}
}