public function break_text()

in admin/AmazonAI-Common.php [1369:1424]


	public function break_text($text)
	{
		$text = str_replace('-AMAZONPOLLY-ONLYAUDIO-START-', '', $text);
		$text = str_replace('-AMAZONPOLLY-ONLYAUDIO-END-', '', $text);
		$text = preg_replace('/-AMAZONPOLLY-ONLYWORDS-START-[\S\s]*?-AMAZONPOLLY-ONLYWORDS-END-/', '', $text);
		$parts = [];
		if (!empty($text)) {
			$part_id = 0;
			$paragraphs = explode("\n", $text);
			foreach($paragraphs as $paragraph) {
				$paragraph_size = strlen(trim($paragraph));
				if ($paragraph_size > 0) {
					if ($paragraph_size <= 2800) {
						$parts[$part_id] = $paragraph . ' **AMAZONPOLLY*SSML*BREAK*time=***500ms***SSML** ';
						$part_id++;
					}
					else {
						$words = explode(' ', $paragraph);
						$current_part = '';
						$last_part = '';
						foreach($words as $word) {
							$word_length = strlen($word);
							$current_part_length = strlen($current_part);
							if ($word_length + $current_part_length < 2800) {
								$current_part = $current_part . $word . ' ';
								$last_part = $current_part;
							}
							else {
								$current_part = $current_part . $word . ' ';
								$parts[$part_id] = $current_part;
								$part_id++;
								$current_part = '';
								$last_part = '';
							}
						}

						$parts[$part_id] = $last_part . ' **AMAZONPOLLY*SSML*BREAK*time=***500ms***SSML** ';
						$part_id++;
					} //end if
				} //end if
			} //end foreach
		} //end if

		// Modify speed

		$parts = $this->modify_speed($parts);

		$logger = new AmazonAI_Logger();

		foreach($parts as $part) {
			$logger->log(sprintf('%s <<< PART >>> ', __METHOD__));
			$logger->log(sprintf('%s', $part));
		}

		return $parts;
	}