从translate.google.com 中提取声音

Dmi*_*iev 3 audio google-chrome

Bunenas tardes se\xc3\xb1ores!

\n

多年来,我通过 Chrome DevTools 和 Network 选项卡从 google.translate.com 中提取声音。单击网络选项卡中的声音按钮时,会出现 mp3 文件。我只需单击它并下载以用于进一步的教育目的。

\n

现在(字面上的今天)只有 XHR 类型的文件,在方括号内有无数的字符序列,就像 JS 数组中的字符串一样。而且页面本身相当复杂。

\n

如何在新的环境下提取声音?

\n
    \n
  • 一些如何从 XHR 文件中提取的信息。
  • \n
  • 可能是在 GNU/Linux 声音系统中录制的某种方式。
  • \n
  • 或者是其他东西。
  • \n
\n

谢谢。

\n

小智 5

php 代码执行此操作:

<?php

$lang = 'en';
$text = 'hello world';

$curl = curl_init();
curl_setopt_array($curl, [
    CURLOPT_URL => 'https://translate.google.com/_/TranslateWebserverUi/data/batchexecute',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => http_build_query([
        'f.req' => json_encode([
            [
                [
                    'jQ1olc',
                    json_encode([
                        $text,
                        $lang,
                        null,
                        json_encode(null),
                    ]),
                    null,
                    'generic',
                ]
            ]
        ]),
    ]),
]);
$response = curl_exec($curl);
curl_close($curl);
if ($response && preg_match('#//NE[^\\\\]+#', $response, $matches)) {
    file_put_contents('test.mp3', base64_decode($matches[0]));
}
else {
    echo "error\n";
}
Run Code Online (Sandbox Code Playgroud)