Can't figure out why there is no output from this request. I loaded a 44100hz mp3 into this. It just outputs an empty object through dd(). I don't think its anything to do with the credentials. As iv enabled the API from the Google Cloud Console.
$speech = new SpeechClient([
'credentials' => storage_path("app/compute/google/cloud/service_accounts/keys/key1.json"),
]);
$file = file_get_contents($options["input_url"]);
// change these variables if necessary
$encoding = AudioEncoding::LINEAR16;
$sampleRateHertz = 44100;
$languageCode = 'en-US';
// get contents of a file into a string
// set string as audio content
$audio = (new RecognitionAudio())
->setContent($file);
// set config
$config = (new RecognitionConfig())
->setEncoding($encoding)
->setSampleRateHertz($sampleRateHertz)
->setLanguageCode($languageCode);
$response = $speech->recognize($config, $audio);
dd(($response->serializeToJsonString()));
foreach ($response->getResults() as $result) {
$alternatives = $result->getAlternatives();
$mostLikely = $alternatives[0];
$transcript = $mostLikely->getTranscript();
$confidence = $mostLikely->getConfidence();
$this->info('Transcript: %s' . PHP_EOL, $transcript);
$this->info('Confidence: %s' . PHP_EOL, $confidence);
}
}
Related
I am using laravel backpack for my site and i need to upload some images, i copy the code from their website and works fine, but i need the original name on the images, i tried some things, but is not working.
public function setImageAttribute($value)
{
$attribute_name = "image";
$disk = "uploads";
$destination_path = 'storage/services/' .date('FY').DIRECTORY_SEPARATOR;
if ($value==null) {
Storage::disk($disk)->delete($this->{$attribute_name});
// set null in the database column
$this->attributes[$attribute_name] = null;
}
if (str_starts_with($value, 'data:image'))
{
$file = $value;
$filename = $this->generateFileName($file, $destination_path);
$image = InterventionImage::make($file)->orientate();
$fullPath = $destination_path.$filename.'.'.$file->getClientOriginalExtension();
$this->attributes[$attribute_name] = $fullPath;
}
protected function generateFileName($file, $destination_path)
{
$filename = basename($file->getClientOriginalName(), '.'.$file->getClientOriginalExtension());
$filename = Str::random(20);
while (Storage::disk('uploads')->exists($destination_path.$filename.'.'.$file->getClientOriginalExtension())) {
$filename = Str::random(20);
}
return $filename;
}
why value alwys take image base64
is there any way to git image original name?
As far as I know, you won't be able to retrieve the filename, as it's always a base64 file. But maybe this work around helps you:
Image fields blade file can be found at:
\vendor\backpack\crud\src\resources\views\crud\fields\image.blade.php
You can overwrite it by making a file on the same name at:
\resources\views\vendor\backpack\crud\fields\image.blade.php
You can change anything there, maybe you can add a hidden input with the file name.
I want to access a Word from A pptx file in laravel using php presentations
I tried this but its not working.Kindly provide any input.
$slides = $oPHPPresentation2->getSlide(7);
$shape=$slides->getShapeCollection();
$paragraphs = $shape->getParagraphs();
foreach ($paragraphs as $paragraph_k => $paragraph_v)
{
$text_elements = $paragraph_v->getRichTextElements();
foreach ($text_elements as $text_element_k => $text_element_v)
{
$text = $text_element_v->getText();
$new_text = str_replace('[[recommendations]]','Pranjal', $text);
$text_element_v->setText($new_text);
}
}
I am uploading a file and saving it in local storage. These files are stored in the database related to a particular user. When i return the last saved user. I get other details in response properly. But instead of the file path. I get the file as response
$file = $request->file('resume');
$profile_id = $request['profile_id'];
$original_name = $_FILES['resume']['name'];
$resume_new_name = str_random(). '.' . $file->getClientOriginalExtension();
$new_file = $request->file('resume')->move('resources/assets/resumes',$resume_new_name);
$candidate_info['resume'] = $new_file;
$candidate = new candidate();
if (empty($candidate_info['name'])) {
$candidate_info['name'] = $candidate_info['email'];
}
$candidate->name = $candidate_info['name'];
$candidate->phone = $candidate_info['phone'];
$candidate->email = $candidate_info['email'];
$candidate->resume = $candidate_info['resume'];
$candidate->client_id = \Auth::user()->id;
$candidate->status = "new";
$candidate->profile_id = $profile_id;
$candidate->save();
return response()->json(['msg' => $candidate]);
In database column 'resume' it stores the path. But in json response it sends the whole file instead of the path. how do i send the path instead of sending the whole file
Just return the value of that one column:
return response()->json(['msg' => $candidate->resume]);
Instead of using move use store
$new_file = $request->file('resume')->store('resources/assets/resumes',$resume_new_name);
I have tried http://docs.joomla.org/Creating_a_file_uploader_in_your_component but first it shows Error: 500 after some research I have removed code
"'.$session->getName().'" : "'.$session->getId().'",
"format" : "raw"
and error is gone. Now Image is not uploading anywhere (I have set path '/images/' folder) I am confuse in code for uploading image PART 5 where to use this code?
function storeImageFile()
{
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder' );
$path = 'PATH_GOES_HERE'.'designs'.DS;
$folder_permissions = "0755";
$folder_permissions = octdec((int)$folder_permissions);
//create folder if not exists
if (!JFolder::exists($path)){
JFolder::create($path, $folder_permissions);
}
$file = JRequest::getVar('design_images', null, 'files',
$count = count($file['name']);
for($i=0;$i<$count;$i++)
{
//$i is the array position of the $_FILES array
if(empty($file['tmp_name'][$i]))
{
return false;
}
//Clean up filename to get rid of strange characters like spaces etc
$filename = JFile::makeSafe($file['name'][$i]);
//setting source and destination
$temporary_name = $file['tmp_name'][$i];
$filename = str_replace(' ', '_', $file['name'][$i]);
$dest = $path.$filename;
if(JFile::upload($temporary_name, $dest))
{
echo "File Upload Successful";
return true;
}
}
}
What I try to accomplish:
Admin creates MS Word document with placeholders that will be filled with data from Joomla database
Admin uploades MS Word file to Joomla and connects it with SQL statement
User execute "Generate MS Word" function and gets MS Word document filled with data from database.
Is there any components for Joomla that does this?
I have done this in my application using Interop libraries.
recently I've done this for a joomla component using phpdocx and pclzip libraries, where
a *.docx file is generated from a template file.
Config:
$params = Object with form data; // data from requeest
$template = 'xml_file_name'; // jfrom xml file name and *.docx template file name
$pl = '#'; // place holder prefix & suffix: (example: #PLACEHOLDER#)
$date_placehold = '#DATE#'; // will be replaced with current date
$date_formt = 'F j, Y'; // php date format
$template_path = JPATH_COMPONENT_SITE .DS.'templates'.DS.$template.'.docx';
$temp_dir = JPATH_ROOT.DS.'tmp'.DS.'phpdocx-temp-dir'; // + write access
$output_mime = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
$filename = $params->first_name .' - '. $params->second_name.'.docx';
// get names of all form fields of type 'list' from xml file
$lists = (array) ComponentHelper::getJFormLists($template);
// get all field names from the xml file
$fields = (array) ComponentHelper::getJFormFieldsNames($template);
Initialize variables:
$doc =& JFactory::getDocument();
$doc->setMimeEncoding($output_mime);
// require phpdocx class
require_once(JPATH_COMPONENT_ADMINISTRATOR . DS . 'helpers'.DS.'pclzip.lib.php');
require_once(JPATH_COMPONENT_ADMINISTRATOR . DS . 'helpers'.DS.'phpdocx.php');
$phpdocx = new phpdocx($template_path, $temp_dir);
bind form fields with user params:
foreach($params as $field => $value)
{
if(array_key_exists($field,$lists) && is_array($lists[$field]) && array_key_exists($value, $lists[$field]) )
{
// if the field is JFormInput with type "list" its value is not important but its label
$var = $lists[$field][$value];
} else {
$var = $value;
}
// use openxml carriage return on new lines
if(strpos($var, "\n")) {
$var = str_replace("\n", '<w:br/>', $var);
}
$fields[$field] = $var;
}
foreach application form fields:
foreach($fields as $field => $value)
{
// replace placeholder with form value
$phpdocx->assign($pl.strtoupper($field).$pl, $value);
}
// assign date for filled-in applications
if(!empty($date_placehold)
{
$phpdocx->assign($date_placehold, date($date_formt));
}
output the file:
$phpdocx->stream($filename, $output_mime);
return true;