https://www.w3schools.com/css/tryit.asp?filename=trycss_table_fancy
sábado, 25 de febrero de 2023
jueves, 23 de febrero de 2023
add html elements clicking a button
<form action="" method="post" id="form">
<div class="textfields-container">
<div class="textfield-container"></div>
</div>
<input type="button" name="addTextfield" id="addTextfield" value="Add Textfield"/>
<input type="submit" value="Submit"/>
</form>
<script>
document.getElementById("addTextfield").addEventListener("click", function(){
var textfield = document.createElement("input");
textfield.type = "text";
textfield.name = "textfield[]";
var textfieldContainer = document.querySelector(".textfields-container");
textfieldContainer.appendChild(textfield);
});
</script>
domingo, 19 de febrero de 2023
upload file
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
check if file is type of image
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "file is an image " . $check['mime'] .".";
$uploadOk = 1;
} else {
echo "file is not an image";
$uploadOk = 0;
}
}
if ($uploadOk == 0) {
echo "problem occured while uploading";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "image file ". basename( $_FILES["fileToUpload"]["name"]). " has been successfully uploaded.";
} else {
echo " problem occured while uploading";
}
}
google tts command
/usr/bin/php /root/google_tts/google_tts_asterisk_es.php "Hola mi nombre es Ambiorix" >/root/google_tts/audios/audio.txt &&
/usr/bin/php /root/google_tts/convert.php audio
/usr/bin/php /root/google_tts/google_tts_asterisk.php "Hello Ambiorix" >/root/google_tts/audios/audio.txt && /usr/bin/php /root/google_tts/convert.php audio
jueves, 9 de febrero de 2023
Sending SMS from csv
<?php
require __DIR__ . "/vendor/autoload.php";
use Telnyx\Api\ApiClient;
use Telnyx\Api\Message;
// Read the csv file
$file = fopen('file.csv', 'r');
// Set the api key
$telnyx = new ApiClient("YOUR_API_KEY");
while (($line = fgetcsv($file)) !== FALSE) {
// Retrieve data from the csv
$phoneNumber = $line[0];
$message = $line[1];
// Send the SMS message
$message = Message::create([
"from" => "+18881234567",
"to" => $phoneNumber,
"text" => $message
]);
echo "\n Sent SMS to {$phoneNumber}: {$message->text}\n";
}
// Close the file
fclose($file);
?>
--------------------------------------------------------------------------------------------------------
This code assumes that the csv file contains data structured like this:
Name, Phone Number
John, +19998881234
Sam, +14447778899
<?php
$csvFile = fopen('contactList.csv', 'r');
$telnyx = new Telnyx\Client('YOUR_TELNYX_API_KEY');
// Iterate over each row in the CSV file
while (($row = fgetcsv($csvFile)) !== FALSE) {
// Set recipient name and number
$name = $row[0];
$number = $row[1];
// Set message body
$message = new Telnyx\SMSMessage(
["from" => "+15551234567",
"to" => $number,
"text" => "Hey, $name! Test message from Telnyx."]
);
// Send the message
$response = $telnyx->SMS->messages->create($message);
}
fclose($csvFile);
?>
martes, 7 de febrero de 2023
google tts and speech api
https://cloud.google.com/text-to-speech/docs/voices
https://cloud.google.com/speech-to-text/docs/speech-to-text-supported-languages
https://cloud.google.com/speech-to-text/docs/transcribe-api
https://cloud.google.com/text-to-speech/docs/libraries#client-libraries-usage-nodejs
https://cloud.google.com/text-to-speech
- Make sure billing is enabled for Speech-to-Text.
- Create and/or assign one or more service accounts to Speech-to-Text.
- Download a service account credential key.
- Set your authentication environment variable.
- (Optional) Create a new Google Cloud Storage bucket to store your audio data.
https://cloud.google.com/speech-to-text/docs/before-you-begin
miércoles, 1 de febrero de 2023
gpt php request
<?php
$url = "https://api.openai.com/v1/completions";
$data = array('prompt' => $argv[1],'max_tokens' =>10, 'model'=> 'text-davinci-003','max_tokens'=>4000,'temperature'=> 1.0);
$encodedData = json_encode($data);
//$data = array(\"param1\" => \"value1\",\"param2\" => \"value2\"\);
$headers = array('Content-Type: application/json','Authorization:Bearer my-key-sdLwvCv');
$curl = curl_init();
$data_string = urlencode(json_encode($data));
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, 1);
//curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl, CURLOPT_POSTFIELDS, $encodedData);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
curl_close($curl);
//echo $response; //uncoment this line if you need log info
$object=json_decode($response);
$array = (array) $object;
$response=(array)$array['choices'][0];
echo $response['text'];
echo "\n";
?>