<commit_before>
/**
 * Media Module: Implementation for Text-To-Speech via MARY TTS
 *
 * @requires CSP for accessing the MARY TTS server, e.g. for default server URL "media-src http://mary.dfki.de:59125/" or "default-src http://mary.dfki.de:59125/"
 *           NOTE if you have configured a different server URL, then that one needs to be enabled via CSP
 *
 */

define(['mmirf/mediaManager', 'mmirf/configurationManager', 'mmirf/languageManager'], function(mediaManager, config, lang){

	/**  @memberOf MaryWebAudioTTSImpl# */
	var _pluginName = 'maryTextToSpeech';

	/**  @memberOf MaryWebAudioTTSImpl# */
	var _defaultServerPath = 'http://mary.dfki.de:59125/';

	/**
	 * separator char for language- / country-code (specific to TTS service)
	 *
	 * @memberOf MaryWebAudioTTSImpl#
	 */
	var _langSeparator = void(0);

	/** @memberOf MaryWebAudioTTSImpl# */
	var _getLangParam;
	/** @memberOf MaryWebAudioTTSImpl# */
	var _getVoiceParam;

	/**
	 * HELPER retrieve language setting and apply impl. specific corrections/adjustments
	 * (i.e. deal with MARY specific quirks for language/country codes)
	 *
	 * @memberOf MaryWebAudioTTSImpl#
	 */
	var _getFixedLang = function(options){

		var locale = _getLangParam(options, _langSeparator);

		return lang.fixLang('mary', locale);
	};

	/**  @memberOf MaryWebAudioTTSImpl# */
	var generateTTSURL = function(text, options){

		text = encodeURIComponent(text);

		var lang = _getFixedLang(options);

		var voice = _getVoiceParam(options);
		var voiceParamStr = voice? '&VOICE='+voice : '';

		return config.get([_pluginName, "serverBasePath"], _defaultServerPath) +'process?INPUT_TYPE=TEXT&OUTPUT_TYPE=AUDIO&INPUT_TEXT=' + text + '&LOCALE='+lang + voiceParamStr + '&AUDIO=WAVE_FILE';
	};

	/**  @memberOf MaryWebAudioTTSImpl# */
	var createAudio = function(sentence, options, onend, onerror, oninit){

		return mediaManager.getURLAsAudio(
				generateTTSURL(sentence, options),
				onend, onerror, oninit
		);

	};

	/**  @memberOf MaryWebAudioTTSImpl# */
	return {
		/**
		 * @public
		 * @memberOf MaryWebAudioTTSImpl.prototype<commit_msg>normalized plugin name and remote URL config-name for mary-tts plugin<commit_after>
/**
 * Media Module: Implementation for Text-To-Speech via MARY TTS
 *
 * @requires CSP for accessing the MARY TTS server, e.g. for default server URL "media-src http://mary.dfki.de:59125/" or "default-src http://mary.dfki.de:59125/"
 *           NOTE if you have configured a different server URL, then that one needs to be enabled via CSP
 *
 */

define(['mmirf/mediaManager', 'mmirf/configurationManager', 'mmirf/languageManager'], function(mediaManager, config, lang){

	/**  @memberOf MaryWebAudioTTSImpl# */
	var _pluginName = 'ttsMary';

	/**  @memberOf MaryWebAudioTTSImpl# */
	var _defaultServerPath = 'http://mary.dfki.de:59125/';

	/**
	 * separator char for language- / country-code (specific to TTS service)
	 *
	 * @memberOf MaryWebAudioTTSImpl#
	 */
	var _langSeparator = void(0);

	/** @memberOf MaryWebAudioTTSImpl# */
	var _getLangParam;
	/** @memberOf MaryWebAudioTTSImpl# */
	var _getVoiceParam;

	/**
	 * HELPER retrieve language setting and apply impl. specific corrections/adjustments
	 * (i.e. deal with MARY specific quirks for language/country codes)
	 *
	 * @memberOf MaryWebAudioTTSImpl#
	 */
	var _getFixedLang = function(options){

		var locale = _getLangParam(options, _langSeparator);

		return lang.fixLang('mary', locale);
	};

	/**  @memberOf MaryWebAudioTTSImpl# */
	var generateTTSURL = function(text, options){

		text = encodeURIComponent(text);

		var lang = _getFixedLang(options);

		var voice = _getVoiceParam(options);
		var voiceParamStr = voice? '&VOICE='+voice : '';

		return config.get([_pluginName, "baseUrl"], _defaultServerPath) +'process?INPUT_TYPE=TEXT&OUTPUT_TYPE=AUDIO&INPUT_TEXT=' + text + '&LOCALE='+lang + voiceParamStr + '&AUDIO=WAVE_FILE';
	};

	/**  @memberOf MaryWebAudioTTSImpl# */
	var createAudio = function(sentence, options, onend, onerror, oninit){

		return mediaManager.getURLAsAudio(
				generateTTSURL(sentence, options),
				onend, onerror, oninit
		);

	};

	/**  @memberOf MaryWebAudioTTSImpl# */
	return {
		/**
		 * @public
		 * @memberOf MaryWebAudioTTSImpl.prototype
{'fraction_non_alphanumeric': 0.12985781990521328, 'fraction_numerical': 0.007582938388625593, 'mean_word_length': 4.370229007633588, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6051503', 'n_tokens_mistral': 1481, 'n_tokens_neox': 1359, 'n_words': 332}