Mix samples using SoX library - php

I have some data for mixer like:
[
{
"sample": "sample1.mp3",
"time": 0
},
{
"sample": "sample2.mp3",
"time": 0.3342
},
{
"sample": "sample3.mp3",
"time": 0.3342,
// stop after means interrupt play this sample on this time in time scale
"stop_after": 0.3442
},
{
"sample": "sample4.mp3",
"time": 1.22443
},
{
"sample": "sample1.mp3",
"time": 1.223434,
"stop_after": 1.224244
}
]
What is the easiest way to create a single file mp3. I will write a wrapper for this on PHP. I just need to understand the right approach and the algorithm for this.

Related

How can I find the middle of a HERE Routing API route?

by doing a GET-Request, I am receiving routing informations from the HERE Routing API:
https://router.hereapi.com/v8/routes?apikey=MY_API_KEY&destination=52.530394,13.400683&origin=52.530728,13.383833&return=polyline,travelSummary&transportMode=truck&&vehicle[speedCap]=30&spans=names,length,duration,speedLimit
Now I want to find the coordinates for example in the middle of the route with respect to the total time. So I the example below, the total duration is 274 seconds. How can I find out, on which position I will be after 137 seconds? (In real application these times are much longer. Here, for simplicity and for a small JSON file size, I have chosen only a short distance)
First, I thought of adding starting and ending coordinates of the spans, however it seems not to be possible with the API.
Second, I thought of using the polyline. From that I receive a lot of coordinates, however I don't see a possiblity to connect one of these coordinates to a certain duration of travel.
Is there any way how I can get the information I am looking for with the HERE Routing API or with any PHP calculation?
{
"routes": [
{
"id": "90be4eb8-d0ba-47f8-9954-9be444576a17",
"sections": [
{
"id": "bfd32e45-662b-4b7e-a297-21eeee09dd68",
"type": "vehicle",
"departure": {
"time": "2021-12-11T23:42:04+01:00",
"place": {
"type": "place",
"location": {
"lat": 52.5307744,
"lng": 13.3838015
},
"originalLocation": {
"lat": 52.5307279,
"lng": 13.383833
}
}
},
"arrival": {
"time": "2021-12-11T23:46:38+01:00",
"place": {
"type": "place",
"location": {
"lat": 52.5303982,
"lng": 13.4006967
},
"originalLocation": {
"lat": 52.5303939,
"lng": 13.4006829
}
}
},
"travelSummary": {
"duration": 274,
"length": 1338,
"baseDuration": 264
},
"polyline": "BGslnmkDyn8wZ8CmL4Iof0F0U8BoGsEoQwCsJsEkSoBoG8BsJsE0U8BgK8BoLoB4IoB0KoBoLoBkNwC8a8B0UoB0UoBkNsEgtBkDsd8BsTkDgZsEgtB4D0jBgFwvBoG46B8B8QwCoV8BwMgFgtBUwHkD8akDgeU4NoB4XAkIoB0ZoB8pBU0K8Boa8B0PkDkS7GkD3I0F3DwC7foa7G0Fzeoaze0ZvTiQ",
"spans": [
{
"offset": 0,
"names": [
{
"value": "Invalidenstraße",
"language": "de"
}
],
"length": 189,
"duration": 31,
"speedLimit": 13.8888893
},
{
"offset": 11,
"names": [
{
"value": "Invalidenstraße",
"language": "de"
}
],
"length": 872,
"duration": 184,
"speedLimit": 8.333334
},
{
"offset": 44,
"names": [
{
"value": "Brunnenstraße",
"language": "de"
}
],
"length": 277,
"duration": 59,
"speedLimit": 8.333334
}
],
"transport": {
"mode": "truck"
}
}
]
}
]
}
Using the information in the spans object is definitely the way to go. What you need is to break up the spans into as many pieces as possible. You can do that by adding these values to the parameter in your request:
&spans=duration,length,segmentId,names,speedLimit,dynamicSpeedInfo,baseDuration,typicalDuration,segmentRef
You'll see that the response includes a list of spans identified by the offset attribute, which tells you what coordinate in your polyline that span refers to. This means that you want to know what is the offset (coordinate index) where the sum of span durations is 137.
This procedure will get you the best approximation to the middle of the route relative to travel time:
Loop through the list of spans and sum the value in the duration attribute; the loop should stop when the sum is equal or greater than the desired duration (137 in your example).
Get the value of the offset attribute, and add 1.
Decode your polyline, and get the coordinates at the index that is equal to the number you got in step 2 (offset + 1).
For the route in your example, the span that meets the condition in step 1 is offset=31, so you're interested in the coordinates at index 32 from your polyline.

Laravel return simplified JSON from query

So I'm performing a query and getting data back like this:
[
{ "part_number": "MAC0009", "description": "Accessory Stand Foot" },
{ "part_number": "MAC0010", "description": "Accessory Stand Collar Tapped M5" },
{ "part_number": "MAC0011", "description": "Accessory Stand Top Collar" },
{ "part_number": "MAC0012", "description": "25mm Round Knob With 2 Rail Holes" }
]
However for the AJAX script I'm trying to implement I need the data in this format:
[
{ "MAC0009" : "Accessory Stand Foot" },
{ "MAC00010" : "Accessory Stand Collar Tapped M5" },
{ "MAC00012" : "Accessory Stand Top Collar" }
]
So basically I need plain data back without the table names.
All I have so far is the query.
$result = DB::table('macs')->select('part_number', 'description')->get();
Which is obviously fine but I don't know how to manipulate the data into that format :/ Any help appreciated.
You can use lists method:
DB::table('macs')->select('part_number', 'description')->lists('description', 'part_number');

JSON Schema Requirement Enforcement

So this is my first time using JSON Schema and I have a fairly basic question about requirements.
My top level schema is as follows:
schema.json:
{
"id": "http://localhost/srv/schemas/schema.json",
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"event": { "$ref": "events_schema.json#" },
"building": { "$ref": "buildings_schema.json#" }
},
"required": [ "event" ],
"additionalProperties": false
}
I have two other schema definition files (events_schema.json and buildings_schema.json) that have object field definitions in them. The one of particular interest is buildings_schema.json.
buildings_schema.json:
{
"id": "http://localhost/srv/schemas/buildings_schema.json",
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "buildings table validation definition",
"type": "object",
"properties": {
"BuildingID": {
"type": "integer",
"minimum": 1
},
"BuildingDescription": {
"type": "string",
"maxLength": 255
}
},
"required": [ "BuildingID" ],
"additionalProperties": false
}
I am using this file to test my validation:
test.json:
{
"event": {
"EventID": 1,
"EventDescription": "Some description",
"EventTitle": "Test title",
"EventStatus": 2,
"EventPriority": 1,
"Date": "2007-05-05 12:13:45"
},
"building": {
"BuildingID": 1,
}
}
Which passes validation fine. But when I use the following:
test2.json
{
"event": {
"EventID": 1,
"EventDescription": "Some description",
"EventTitle": "Test title",
"EventStatus": 2,
"EventPriority": 1,
"Date": "2007-05-05 12:13:45"
}
}
I get the error: [building] the property BuildingID is required
Inside my buildings_schema.json file I have the line "required": [ "BuildingID" ] which is what causes the error. It appears that the schema.json is traversing down the property definitions and enforcing all the requirements. This is counter intuitive and I would like it to ONLY enforce a requirement if it's parent property is enforced.
I have a few ways around this that involve arrays and fundamentally changing the structure of the JSON, but that kind of defeats the purpose of my attempts at validating existing JSON. I have read over the documentation (/sigh) and have not found anything relating to this issue. Is there a some simple requirement inheritance setting I am missing?
I am using the Json-Schema for PHP implementation from here: https://github.com/justinrainbow/json-schema
After messing with different validators, it appears to be an issue with the validator. The validator assumes required inheritance through references. I fixed this by simply breaking apart the main schema into subschemas and only using the required subschema when necessary.

How may i retrieve Mysql data to this JSON format?

I have read about json_encode but still lack the logic in using it for my needs on this particular JSON structure.
Assuming the JSON structure is as follows :
{
"_id": "23441324",
"api_rev": "1.0",
"type": "router",
"hostname": "something",
"lat": -31.805412,
"lon": -64.424677,
"aliases": [
{
"type": "olsr",
"alias": "104.201.0.29"
}
],
"site": "roof town hall",
"community": "Freifunk/Berlin",
"attributes": {
"firmware": {
"name": "meshkit",
"url": "http:k.net/"
}
}
}
Some of the values of the attributes will be taken from the database while some are going to be hardcoded(static) like "type","api_rev". I was thinking of just using concatenation to build the structure but learnt its a bad idea. So if i am to use json_encode how may i be able to handle this structure ? array dimensions etc.

PHP parse facebook json

I've search Stack Overflow and Google for an answer but not luck. I'm trying to get the value of each of the locale with php in the following sample (facebook graph api). Any help would be appreciated.
"data": [
{
"id": "123456789/insights/page_fans_locale/lifetime",
"name": "page_fans_locale",
"period": "lifetime",
"values": [
{
"value": {
"en_US": 33975,
"fr_CA": 6906,
"fr_FR": 6105,
"en_GB": 5647
},
"end_time": "2012-03-14T07:00:00+0000"
},
{
"value": {
"en_US": 33992,
"fr_CA": 6906,
"fr_FR": 6107,
"en_GB": 5648
},
"end_time": "2012-03-15T07:00:00+0000"
},
}
First, this fragment is broken. data is a array not a JavaScript object.
Take the correct fragment and analyze data correctly. The best option is:
json_decode();
Here is how to use it.

Categories