Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[voicerss] Fix bad audio format code and use HTTPS URL instead of HTTP #12092

Merged
merged 1 commit into from
Jan 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private String getApiAudioFormat(AudioFormat format) throws TTSException {
case AudioFormat.CODEC_MP3:
case AudioFormat.CODEC_VORBIS:
case AudioFormat.CODEC_AAC:
return apiFrequency + "_" + bitDepth + "_mono";
return apiFrequency + "_" + bitDepth + "bit_mono";
default:
throw new TTSException("Unsupported audio format: " + format);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public class VoiceRSSCloudImpl implements VoiceRSSCloudAPI {

public static final String DEFAULT_VOICE = "default";

public static final String API_URL = "https://api.voicerss.org/?key=%s&hl=%s&c=%s&f=%s&src=%s";
public static final String API_URL_WITH_VOICE = API_URL + "&v=%s";

private final Logger logger = LoggerFactory.getLogger(VoiceRSSCloudImpl.class);

private static final Set<AudioFormat> SUPPORTED_AUDIO_FORMATS = Set.of(
Expand Down Expand Up @@ -285,12 +288,12 @@ public InputStream getTextToSpeech(String apiKey, String text, String locale, St
private String createURL(String apiKey, String text, String locale, String voice, String audioCodec,
String audioFormat) {
String encodedMsg = URLEncoder.encode(text, StandardCharsets.UTF_8);
String url = "http://api.voicerss.org/?key=" + apiKey + "&hl=" + locale + "&c=" + audioCodec + "&f="
+ audioFormat;
String url;
if (!DEFAULT_VOICE.equals(voice)) {
url += "&v=" + voice;
url = String.format(API_URL_WITH_VOICE, apiKey, locale, audioCodec, audioFormat, encodedMsg, voice);
} else {
url = String.format(API_URL, apiKey, locale, audioCodec, audioFormat, encodedMsg);
}
url += "&src=" + encodedMsg;
return url;
}
}