Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

How can I reduce the time taken by wav file to save in /tmp folder

by srikanth (Initiate)
on Dec 03, 2021 at 05:45 UTC ( [id://11139350]=perlquestion: print w/replies, xml ) Need Help??

srikanth has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on How can I reduce the time taken by wav file to save in /tmp folder
  • Download Code

Replies are listed 'Best First'.
Re: How can I reduce the time taken by wav file to save in /tmp folder
by dave_the_m (Monsignor) on Dec 03, 2021 at 09:17 UTC
    You posted the same question yesterday on stack overflow, then ignored the comments asking you for more information.

    Dave.

Re: How can I reduce the time taken by wav file to save in /tmp folder
by Corion (Patriarch) on Dec 03, 2021 at 08:38 UTC

    From your code, I'm a bit unclear as to which part actually takes too long.

    Is it this line?

    my $response = $ua->get("http://127.0.0.1:8000/speech_to_text/?file_pa +th=$tmpname.wav");

    ... or is there anything else?

    I'm not sure how AGI programs work. Maybe you can only send one action per invocation, so you have then to find out when recording the file ended?

      print "RECORD FILE $tmpname wav \"$intkey\" \"$abs_timeout\" $beep \"$silence\"\n"; this is the line which is taking time to create file

        I would think this takes time to create because it is writing the file while recording. If you record 60 seconds, the file will take 60 seconds to create.

        Do you expect something different?

        That just looks like a print statement to me. I don't see anything that should "take time". STDOUT is buffered. Buffering can cause a delay in writing to the screen and make it look like something took a long time when in fact it didn't. Add this line: $|=1; at the top of your Perl code. That will turn off buffering.
Re: How can I reduce the time taken by wav file to save in /tmp folder
by davido (Cardinal) on Dec 03, 2021 at 16:11 UTC

    How is the code you posted related to the act of saving to a tempfile? Or are we supposed to just imagine that part?


    Dave

Re: How can I reduce the time taken by wav file to save in /tmp folder
by Marshall (Canon) on Dec 03, 2021 at 21:16 UTC
    my ($fh, $tmpname) = tempfile("stt_XXXXXX", DIR => $tmpdir, UNLINK => 1);

    Ok, you ask for a temp file to be created in a particular directory and for that temp file to be deleted automatically when $fh goes out of scope.

    What does @result = checkresponse(); do?
    Where are you using the temp filehandle, $fh?

    I don't know how big this .wav file is? Downloading the entire file and then processing the entire downloaded file is one thing. Overlapping the start of processing while the download is still going on is a very different matter. I don't see anything here that reflects that level of complexity.

    Update: Out of curiosity, why would you specify your own temp dir? Why not use the system provided one? If your program "dies", a useless file may be left in that directory that standard "clean up" utilities will not detect.

Re: How can I reduce the time taken by wav file to save in /tmp folder
by kikuchiyo (Hermit) on Dec 04, 2021 at 18:18 UTC

    It's hard to tell what you are trying to do, chances are that you haven't the slightest idea either, but I'm going to take a shot in the dark:

    is the problem that you cannot reliably tell when has Asterisk finished with the recording?

    In that case I'd recommend moving any kind of postprocessing out of the dialplan, AGI handlers etc. Instead, do it in a completely separate process, and use inotify with a IN_CLOSE_WRITE event mask to to monitor for files. In my experience once Asterisk closes a recording it doesn't reopen it, so it's safe to do any postprocessing steps (transcoding, speech-to-text, uploading etc.) on it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11139350]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-25 23:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found