php - How can I make my script faster. One part takes 3 seconds alone -
after checking code found why taking 7 seconds load wish pain..
$target_path = "uploads/"; exec("./speechdetect.sh uploads/voice.3gp > speech.results"); $myfile = "uploads/voice.3gp"; unlink($myfile); $myfile = "voice.flac"; unlink($myfile); $target_path = $target_path . basename( $_files['uploadedfile']['name']); my script takes voice recording , sends google via speechdetect.sh. takes text googled translated speak , programme matches , executes command accordingly such radio on.
how can create faster improve or more efficient want fast page loading time im using lighttpd.
p.s without section of code page loads in 352ms.
also shell code is
#!/bin/bash sudo rm voice.flac # flac encoded illustration ffmpeg -i $1 voice.flac curl \ --data-binary @voice.flac \ --header 'content-type: audio/x-flac; rate=8000' \ 'https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&pfilter=0&lang=en-gb&maxresults=1'
i guess it's "speechdetect.sh" script takes lot of time. should seek optimize shell script if possible. slow anyhow because have connect remotely google, upload data, google needs time process info , takes time send you.
the factors are: bandwidth, latency, google's performance in processing data.
the best thing create waiting more pleasent. execute script in iframe, or load via ajax if possible , show kind of loading indicator user knows going on.
edit:
ok, maybe ffmpeg 1 blame, because ffmpeg can slow - loads lot of code when started.
try benchmark script:
measure time script consumes.
start shell this:
time ./speechdetect.sh uploads/voice.3gp > speech.results
this should output like:
real 0m1.005s user 0m0.000s sys 0m0.008s the real part actual execution time (1.005 seconds in example). more info check out man page
make simple benchmark in php script
$target_path = "uploads/"; $time_start = microtime(true); exec("./speechdetect.sh uploads/voice.3gp > speech.results"); $time_end = microtime(true); $time = $time_end - $time_start; echo "time elapsed: " . $time . " seconds"; // .... get more detailed info whether upload google or ffmpeg consumes time:
modify shell script (added time):
#!/bin/bash sudo rm voice.flac # flac encoded illustration time ffmpeg -i $1 voice.flac time curl \ --data-binary @voice.flac \ --header 'content-type: audio/x-flac; rate=8000' \ 'https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&pfilter=0&lang=en-gb&maxresults=1' run it: ./speechdetect.sh uploads/voice.3gp (without redirecting output)
the first time benchmark shown 1 of ffmpeg , sec 1 phone call curl
php lighttpd
No comments:
Post a Comment