Chris@76: 2 || ($ip2 = cache_get_data('wave_file/' . $user_info['ip2'], 20)) > 2) Chris@76: die(header('HTTP/1.1 400 Bad Request')); Chris@76: cache_put_data('wave_file/' . $user_info['ip'], $ip ? $ip + 1 : 1, 20); Chris@76: cache_put_data('wave_file/' . $user_info['ip2'], $ip2 ? $ip2 + 1 : 1, 20); Chris@76: Chris@76: // Fixate randomization for this word. Chris@76: mt_srand(end(unpack('n', md5($word . session_id())))); Chris@76: Chris@76: // Try to see if there's a sound font in the user's language. Chris@76: if (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.' . $user_info['language'] . '.wav')) Chris@76: $sound_language = $user_info['language']; Chris@76: Chris@76: // English should be there. Chris@76: elseif (file_exists($settings['default_theme_dir'] . '/fonts/sound/a.english.wav')) Chris@76: $sound_language = 'english'; Chris@76: Chris@76: // Guess not... Chris@76: else Chris@76: return false; Chris@76: Chris@76: // File names are in lower case so lets make sure that we are only using a lower case string Chris@76: $word = strtolower($word); Chris@76: Chris@76: // Loop through all letters of the word $word. Chris@76: $sound_word = ''; Chris@76: for ($i = 0; $i < strlen($word); $i++) Chris@76: { Chris@76: $sound_letter = implode('', file($settings['default_theme_dir'] . '/fonts/sound/' . $word{$i} . '.' . $sound_language . '.wav')); Chris@76: if (strpos($sound_letter, 'data') === false) Chris@76: return false; Chris@76: Chris@76: $sound_letter = substr($sound_letter, strpos($sound_letter, 'data') + 8); Chris@76: switch ($word{$i} === 's' ? 0 : mt_rand(0, 2)) Chris@76: { Chris@76: case 0: Chris@76: for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) Chris@76: for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++) Chris@76: $sound_word .= $word{$i} === 's' ? $sound_letter{$j} : chr(mt_rand(max(ord($sound_letter{$j}) - 1, 0x00), min(ord($sound_letter{$j}) + 1, 0xFF))); Chris@76: break; Chris@76: Chris@76: case 1: Chris@76: for ($j = 0, $n = strlen($sound_letter) - 1; $j < $n; $j += 2) Chris@76: $sound_word .= (mt_rand(0, 3) == 0 ? '' : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j + 1} : $sound_letter{$j}) . (mt_rand(0, 3) === 0 ? $sound_letter{$j} : $sound_letter{$j + 1}) . $sound_letter{$j + 1} . (mt_rand(0, 3) == 0 ? $sound_letter{$j + 1} : ''); Chris@76: $sound_word .= str_repeat($sound_letter{$n}, 2); Chris@76: break; Chris@76: Chris@76: case 2: Chris@76: $shift = 0; Chris@76: for ($j = 0, $n = strlen($sound_letter); $j < $n; $j++) Chris@76: { Chris@76: if (mt_rand(0, 10) === 0) Chris@76: $shift += mt_rand(-3, 3); Chris@76: for ($k = 0, $m = round(mt_rand(15, 25) / 10); $k < $m; $k++) Chris@76: $sound_word .= chr(min(max(ord($sound_letter{$j}) + $shift, 0x00), 0xFF)); Chris@76: } Chris@76: break; Chris@76: Chris@76: } Chris@76: Chris@76: $sound_word .= str_repeat(chr(0x80), mt_rand(10000, 10500)); Chris@76: } Chris@76: Chris@76: $data_size = strlen($sound_word); Chris@76: $file_size = $data_size + 0x24; Chris@76: $sample_rate = 16000; Chris@76: Chris@76: // Disable compression. Chris@76: ob_end_clean(); Chris@76: header('Content-Encoding: none'); Chris@76: Chris@76: // Output the wav. Chris@76: header('Content-type: audio/x-wav'); Chris@76: header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 525600 * 60) . ' GMT'); Chris@76: header('Content-Length: ' . ($file_size + 0x08)); Chris@76: Chris@76: echo pack('nnVnnnnnnnnVVnnnnV', 0x5249, 0x4646, $file_size, 0x5741, 0x5645, 0x666D, 0x7420, 0x1000, 0x0000, 0x0100, 0x0100, $sample_rate, $sample_rate, 0x0100, 0x0800, 0x6461, 0x7461, $data_size), $sound_word; Chris@76: Chris@76: // Noting more to add. Chris@76: die(); Chris@76: } Chris@76: Chris@76: ?>