Waveform for audio file in magento - json

My file is already save. I have file name and file url. for generate waveform i want this type of code.
[0.75827,0.502991,0.765717,0.68399,0.798004,.....]
i think this is json of audio file. how can i get this type of json of audio file

I think what you want is to create an array of numbers based on an audiofile to represent the contents of your audio file. You should probably just check the answer on this question which seem to work just fine for that:
https://stackoverflow.com/questions/2381243/how-does-soundcloud-com-generate-the-waveform-for-their-mp3-player
They mention this project does the job (to generate the waveform):
https://github.com/afreiday/php-waveform-png
If you specifically want the array of numbers, you can change the code to store or return the variable $v from this line:
$v = (int) ($data / 255 * $height);
From:
https://github.com/afreiday/php-waveform-png/blob/master/php-waveform-png.php

Related

How to export .csv files using a script in Dymola?

I am running a big set of simulations in Dymola using a script, so far, it works well.
However, it remains incomplete because all the results are still in .mat and I have not find a way to automatically save them as .csv.
I found the DataFiles.convertMATtoCSV() function, but it requires me to specify a list of variables to export. I would like it to export all the variables without writing them one by one, is it possible?
In the Dymola Manual, there is a section "Saving all values into a CSV file".
It contains the following example code:
// Define name of trajectory file (fileName) and CVS file
// (CSVfile)
fileName="PID_Controller.mat";
CSVfile="AllVariables.csv";
// Read the size of the trajectories in the result file and
// store in 'n'
n=readTrajectorySize(fileName);
// Read the names of the trajectories
names = readTrajectoryNames(fileName);
// Read the trajectories 'names' (and store in 'traj')
traj=readTrajectory(fileName,names,n);
// transpose traj
traj_transposed=transpose(traj);
// write the .csv file using the package 'DataFiles'
DataFiles.writeCSVmatrix(CSVfile, names, traj_transposed);
This should do what you want. Also it gives room for customization if necessary later...

Opensmile: unreadable csv file while extracting prosody features from wav file

I am extracting prosody features from an audio file while using Opensmile using Windows version of Opensmile. It runs successful and an output csv is generated. But when I open csv, it shows some rows that are not readable. I used this command to extract prosody feature:
SMILEXtract -C \opensmile-3.0-win-x64\config\prosody\prosodyShs.conf -I audio_sample_01.wav -O prosody_sample1.csv
And the output of csv looks like this:
[
Even I tried to use the sample wave file given in Example audio folder given in opensmile directory and the output is same (not readable). Can someone help me in identifying where the problem is actually? and how can I fix it?
You need to enable the csvSink component in the configuration file to make it work. The file config\prosody\prosodyShs.conf that you are using does not have this component defined and always writes binary output.
You can verify that it is the standart binary output in this way: omit the -O parameter from your command so it becomesSMILEXtract -C \opensmile-3.0-win-x64\config\prosody\prosodyShs.conf -I audio_sample_01.wav and execute it. You will get a output.htk file which is exactly the same as the prosody_sample1.csv.
How output csv? You can take a look at the example configuration in opensmile-3.0-win-x64\config\demo\demo1_energy.conf where a csvSink component is defined.
You can find more information in the official documentation:
Get started page of the openSMILE documentation
The section on configuration files
Documentation for cCsvSink
This is how I solved the issue. First I added the csvSink component to the list of the component instances. instance[csvSink].type = cCsvSink
Next I added the configuration parameters for this instance.
[csvSink:cCsvSink]
reader.dmLevel = energy
filename = \cm[outputfile(O){output.csv}:file name of the output CSV
file]
delimChar = ;
append = 0
timestamp = 1
number = 1
printHeader = 1
\{../shared/standard_data_output_lldonly.conf.inc}`
Now if you run this file it will throw you errors because reader.dmLevel = energy is dependent on waveframes. So the final changes would be:
[energy:cEnergy]
reader.dmLevel = waveframes
writer.dmLevel = energy
[int:cIntensity]
reader.dmLevel = waveframes
[framer:cFramer]
reader.dmLevel=wave
writer.dmLevel=waveframes
Further reference on how to configure opensmile configuration files can be found here

Does anyone have a script to convert a Chrome Bookmarks file with [sub]*folders into a CVS file?

I want to be able to do Vimdiffs and Vimfolds on Bookmarks files that have been converted to CVS files ie with one description and one uri per line. However, because the Bookmarks file has multiple levels for the folders, the CSV file will also need fields for the different levels of folder names on each line.
I am new to jq but it seems like it should be able to do this sort of conversion?
Thanks,
Phil.
Have you tried to use any free tools like: https://json-csv.com/
or json2csv: https://www.npmjs.com/package/json2csv
If neither of those works, perhaps this approach.
When I need to reconstruct data I write a set of loops that identify each property I want for each line in my CSV. Let's say my JSON has Name, Email, Phone but for some reason all are at different object levels in my JSON.
First right a loop that resolves Name, then a loop for Email, and one for Phone. At the end of the first loop call the second, and from the second call the third.
Then you can use jq -n which allows to create JSON with no input.
So your CSV output would be like jq -n '{NewName: .["'$Name'"]}'
once you have a clean JSON with all data points at the same level CSV conversion is smooth.
Hope this helps

Reading all CSV files in current working directory into pandas with correct filenames

I'm trying to use a loop to read in multiple CSVs (for now but mix of that and xls in the future).
I'd like each data frame in pandas to be the same name excluding file extension in my folder.
import os
import pandas as pd
files = filter(os.path.isfile, os.listdir( os.curdir ) )
files # this shows a list of the files that I want to use/have in my directory- they are all CSVs if that matters
# i want to load these into pandas data frames with the corresponding filenames
# not sure if this is the right approach....
# but what is wrong is the variable is named 'weather_today.csv'... i need to drop the .csv or .xlsx or whatever it might be
for each_file in files:
frame = pd.read_csv( each_file)
each_file = frame
Bernie seems to be great but one problem:
or each_file in files:
frame = pd.read_csv(each_file)
filename_only = os.path.splitext(each_file)[0]
# Right below I am assigning my looped data frame the literal variable name of "filename_only" rather than the value that filename_only represents
#rather than what happens if I print(filename_only)
filename_only = frame
for example if my two files are weather_today, earthquakes.csv (in that order) in my files list, then both 'earthquakes' and 'weather' will not be created.
however, if I simply type 'filename_only' and click the enter key in python - then I will see the earthquake dataframe. If I have 100 files, then the last data frame name in the list loop will be titled 'filename_only' and the other 99 won't because the previous assignments are never made and the 100th one overwrites them.
You can use os.path.splitext() for this to "split the pathname path into a pair (root, ext) such that root + ext == path, and ext is empty or begins with a period and contains at most one period."
for each_file in files:
frame = pd.read_csv(each_file)
filename_only = os.path.splitext(each_file)[0]
filename_only = frame
As asked in a comment we would like a way to filter for just CSV files so you can do something like this:
files = [file for file in os.listdir( os.curdir ) if file.endswith(".csv")]
Use a dictionary to store your frames:
frames = {}
for each_file in files:
frames[os.path.splitext(each_file)[0]] = pd.read_csv(each_file)
Now you can get the DataFrame of your choice with:
frames[filename_without_ext]
Simple, right? Be careful about RAM usage though, reading a bunch of files can quickly fill up system memory and cause a crash.

How to store image in database

I am trying to insert image in database. The database has a field named images and its type is BLOB. I am trying to insert the image, but only the first 2.2KB is stored. Even if I insert another image it stores only 2.2KB in the database.
When I try to show this image in my application it doesn't show; it's just a small icon, not the image. How can I insert the image in the right way?
use CGI;
my $file = $q->param("file");
$file = 'C:/wamp/bin/apache/apache2.2.22/cgi-bin/images/2.jpg';
open(my $fh, $file);
my $data;
binmode($fh);
read($fh, $data, (stat($fh))[7]);
close($fh);
my $Data = {
table =>'student',
data => {
Image => $fh,
}
};
Data::Insert($Data);
print $q->header;
print $q->start_html(
-title => "student",
);
print $q->end_html;
showImage.pl
my $q = new CGI();
my $handle = Dbm::connection();
$id = $q->param('id_person');
$getimage = $handle->selectrow_array (<<SQLEOF);
SELECT Image
FROM student
WHERE ID = '$id'
SQLEOF
print "Content-Type: image/jpeg\n";
print "Content-length: \n\n";
binmode STDOUT;
print STDOUT $getimage;
My recomendation is keep the image as base 64 encrypted to the db with the MIME type of the image. When you need it, just decrypt it by saying MIME type. This is the mostly used to upload files using ajax. So why can't we use the same way to store image directly to DB?
Just give an additional column to keep MIME type in your table and take it along with the encoded data as print it together.
From a file extension, we can identify the type of file. The MIME type for images are mainly
image/gif: GIF image
image/jpeg: JPEG JFIF image;
image/pjpeg: JPEG JFIF image;
image/png: Portable Network Graphics;
image/svg+xml: SVG vector image;
image/tiff: Tag Image File Format (only for Baseline TIFF);
You can create a new column by giving name as mime_typ . Now when you enctrypt a file using base 64 encryption, keep it as a string like we store usernames and passwords in a table. Similarly add the MIME type to the mime_typ column. when you want to show the image, print the encrypted content after decoding it along with the content in the MIME type, which is stored in the same row in the mime_typ column. You can search google for the way to show an image which is encrypted in base 64 encryption.
You need to read the file in binary mode - i.e.
open(my $fh, $myfile);
my $data;
binmode($fh);
read($fh, $data, (stat($fh))[7]);
close($fh);
I'm not sure why you deleted the database-insert code from the question, but I found it in the revision history.
The issue could be because you aren't not using bind variables, and the binary image contains an escape character which is causing a problem.
I recommend using DBIx::Simple to help create your insert statements that will help create the bind variables for you. DBIx::Simple works with both SQL::Abstract and SQL::Interp. I find SQL::Interp more flexible.
It also appears to be a bug that you are inserting the file handle into the image field instead of the file data. Try adding use File::Slurp (which you may need to install), and then putting this in your %data hash:
Image => scalar read_file($file, { binmode => ':raw' });
Your SELECT statement is also vulnerable to a SQL injection attack because you did not validate the outside input before passing it to the database, and you did not you bind variables again. Using DBIx::Simple, the same code would look like this:
my $db = DBIx::Simple->new($handle);
$getimage = $db->iquery("SELECT Image FROM student WHERE ID = ",\$id)->list;
Also, I recommend omitting the Content-Length header, or properly calculating it, rather than leaving it present in an invalid state.