mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2026-01-06 11:43:50 +00:00
Add Google API v2 speech transcription
This commit is contained in:
@@ -139,11 +139,21 @@ if (!function_exists('transcribe')) {
|
||||
//$command = "curl -X POST -silent -u \"apikey:".$api_key."\" --header \"Content-type: ".$content_type."\" --data-binary @".$file_path."/".$file_name." \"".$api_url."\"";
|
||||
//echo "command: ".$command."\n";
|
||||
|
||||
$command = "sox ".$file_path."/".$file_name." ".$file_path."/".$file_name.".flac trim 0 00:59 ";
|
||||
$command .= "&& echo \"{ 'config': { 'languageCode': '".$transcribe_language."', 'enableWordTimeOffsets': false , 'enableAutomaticPunctuation': true , 'alternativeLanguageCodes': '".$transcribe_alternate_language."' }, 'audio': { 'content': '`base64 -w 0 ".$file_path."/".$file_name.".flac`' } }\" ";
|
||||
$command .= "| curl -X POST -H \"Content-Type: application/json\" -d @- ".$api_url.":recognize?key=".$api_key." ";
|
||||
$command .= "&& rm -f ".$file_path."/".$file_name.".flac";
|
||||
echo $command."\n";
|
||||
//api version 1
|
||||
if (substr($api_url, 0, 32) == 'https://speech.googleapis.com/v1') {
|
||||
$command = "sox ".$file_path."/".$file_name." ".$file_path."/".$file_name.".flac trim 0 00:59 ";
|
||||
$command .= "&& echo \"{ 'config': { 'languageCode': '".$transcribe_language."', 'enableWordTimeOffsets': false , 'enableAutomaticPunctuation': true , 'alternativeLanguageCodes': '".$transcribe_alternate_language."' }, 'audio': { 'content': '`base64 -w 0 ".$file_path."/".$file_name.".flac`' } }\" ";
|
||||
$command .= "| curl -X POST -H \"Content-Type: application/json\" -d @- ".$api_url.":recognize?key=".$api_key." ";
|
||||
$command .= "&& rm -f ".$file_path."/".$file_name.".flac";
|
||||
echo $command."\n";
|
||||
}
|
||||
|
||||
//api version 2
|
||||
if (substr($api_url, 0, 32) == 'https://speech.googleapis.com/v2') {
|
||||
$command = "echo \"{ 'config': { 'auto_decoding_config': {}, 'language_codes': ['".$transcribe_language."'], 'model': 'long' }, 'content': '`base64 -w 0 ".$file_path."/".$file_name.".wav`' } }\" ";
|
||||
$command .= "| curl -X POST -H \"Content-Type: application/json\" -H \"Authorization: Bearer ".$api_key."\" -d @- ".$api_url;
|
||||
echo $command."\n";
|
||||
}
|
||||
|
||||
//ob_start();
|
||||
//$result = passthru($command);
|
||||
|
||||
Reference in New Issue
Block a user