Open priya-zha opened 11 months ago
Fixed solution:
we can add textToSpeech.setVoice(getDesiredVoice(selectedVoice)); when the radiobutton is clicked.
voiceRadioGroup.setOnCheckedChangeListener((group, checkedId) -> {
RadioButton selectedRadioButton = findViewById(checkedId);
selectedRadioButton.setBackgroundResource(R.drawable.radio_button);
String selectedVoice = selectedRadioButton.getText().toString().toLowerCase();
textToSpeech.setVoice(getDesiredVoice(selectedVoice));
if (selectedVoice.equals("men")){
textToSpeech.speak("You have selected the male voice.", TextToSpeech.QUEUE_FLUSH, null);
}
else{
textToSpeech.speak("You have selected the female voice.", TextToSpeech.QUEUE_FLUSH, null);
}
// Update the ImageView based on the selected voice
int imageResource = (selectedVoice.equals("men")) ? R.drawable.male_image : R.drawable.female_image;
voiceImageView.setImageResource(imageResource);
});
private void playSampleVoice() {
// Get the selected radio button
RadioButton selectedRadioButton = findViewById(voiceRadioGroup.getCheckedRadioButtonId());
// Get the text of the selected radio button
String selectedVoice = selectedRadioButton.getText().toString().toLowerCase();
// Set the desired voice based on the selected voice
textToSpeech.setVoice(getDesiredVoice(selectedVoice));
// Define the sample text
String sampleText = (selectedVoice.equals("men")) ? "This is a sample male voice." : "This is a sample female voice.";
// Speak the sample text with the specified voice
HashMap<String, String> params = new HashMap<>();
String utteranceId = (selectedVoice.equals("men")) ? "maleVoice" : "femaleVoice";
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, utteranceId);
textToSpeech.speak(sampleText, TextToSpeech.QUEUE_FLUSH, params);
}
// Get the desired voice based on the selected voice
private Voice getDesiredVoice(String selectedVoice) {
if (selectedVoice.equals("men")) {
// Assign the male voice using Voice
return new Voice("hi-in-x-hie-local", new Locale("hi_IN"), 400, 200, false, new HashSet<>());
} else {
// Assign the female voice using Voice
// return new Voice("com.google.android.tts:en-in-x-ene-network", new Locale("en_IN"), 400, 200, false, new HashSet<>());
//
Voice defaultFemaleVoice = textToSpeech.getDefaultVoice();
return defaultFemaleVoice;
}
}
Steps to reproduce: Click on male/female radiobuttons and notice female voice is given as an output.
Actual Result: Clicking on male or female radio buttons reads the screen in a female voice instead of reading screen in male voice if male radiobutton is selected and reading screen in female voice if female radiobutton is selected. It should work in a similar way how voice changes when voice input is given by the user. (Works fine on voice input but not on when radiobuttons are clicked)
Expected Result: Similar to voice input, if male radiobutton is clicked, male sample voice should be played, and if female radiobutton is clicked, female sample voice should be played.
Before Fixing:
https://github.com/priya-zha/Software-Engineering-Project/assets/34065075/bf94728c-6e70-4619-9809-9b0b1e30d052
After Fixing:
https://github.com/priya-zha/Software-Engineering-Project/assets/34065075/1b9ed7f9-035d-4a52-9528-9049632e67a8