繁体   English   中英

Google Speech to Text 与 Asterisk 实时通话的集成

[英]Google Speech to Text integration with Asterisk live calls

我已经设置了谷歌语音来测试星号。 我已完成以下操作以将语音转换为文本。

当来电时,我记录消息,使用 sox 转换为谷歌支持的比特率音频文件,将音频文件发送到谷歌云语音并获得响应。

无论如何,我们可以发送实时通话音频而不是录制到谷歌云速度并获得响应吗? 请看我下面的代码。

<?php
        require_once('/scripts/phpagi/phpagi.php');

$agi = new AGI();
$agi->answer();

$unique_id = "$argv[1]";
$caller_id = "$argv[2]";

$agi->record_file("/scripts/google-speech-to-text/recordings/$unique_id-$caller_id","wav",' ',-1,null,false,5);


echo system("sox /scripts/google-speech-to-text/recordings/$unique_id-$caller_id.wav -b 16 -s -c 1 -r 16k -t raw /scripts/google-speech-to-text/recordings/$unique_id-$caller_id.raw");

putenv('GOOGLE_APPLICATION_CREDENTIALS=/scripts//file.json');

# Includes the autoloader for libraries installed with composer
require __DIR__ . '/vendor/autoload.php';

# Imports the Google Cloud client library
use Google\Cloud\Speech\SpeechClient;

# Your Google Cloud Platform project ID
$projectId = 'myprojectid';

# Instantiates a client
$speech = new SpeechClient([
    'projectId' => $projectId,
    'languageCode' => 'en-US',
]);

# The name of the audio file to transcribe
$fileName = '/scripts/google-speech-to-text/recordings/$unique_id-$caller_id.raw';

# The audio file's encoding and sample rate
$options = [
    'encoding' => 'LINEAR16',
    'sampleRateHertz' => 16000,
    'model' => 'phone_call',
];

# Detects speech in the audio file
$results = $speech->recognize(fopen($fileName, 'r'), $options);

foreach ($results as $result) {
$getresult =  $result->alternatives()[0]['transcript'] ;

}

echo $getresult;
?>

是的,您可以使用 EAGI 进行连续识别。

不幸的是,它目前还不够稳定(进行核心转储等)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM