0

I am automating a Voice Search functionality using selenium and FreeTTS. I have set everything up, but when I run, I get error:

java.lang.Error: Unable to load voice directory. java.lang.ClassNotFoundException: com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory

This is the code:

speakutil.java:

package examplelayer.AbstractComponents;


import com.sun.speech.freetts.VoiceManager;


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("kevin");
            systemVoice.allocate();
        }
        
        public  static void speak(String text){
            systemVoice.speak(text);
        }
        
        public static void deallocate(){
            systemVoice.deallocate();
        }
    }

I am calling it in this file:

voiceSearchTest:

public class voiceSearchTest  {
    
    @BeforeClass
    public void setup(){
        speakUtil.allocate();
    }
    
    
    @Test(dataProvider = "voiceSearch")
    public void voiceSearch(String searchText) throws InterruptedException {
        
        
        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);      

        
        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);
        
        MXPlayer.pageobjects.voiceSearch voicesearch = new MXPlayer.pageobjects.voiceSearch(driver); 
        
        
        voicesearch.searchClick();
        voicesearch.voiceClick();
        speakUtil.speak(searchText);
        
        voicesearch.startListening();
        voicesearch.startListening();
        voicesearch.getVoiceSearchText();
        
        
        
    }
    
    @DataProvider(name = "voiceSearch")
    public Object[][] voiceSearch2(){
           return new Object[][] {
                   {"CircleVideo"}, 
                  
           };
        }
    
     @AfterClass
        public void deallocate(){
            speakUtil.deallocate();
        }

}
Azpect
  • 43
  • 6

0 Answers0