discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Clipping and Renaming wavesink output file


From: Jeff Long
Subject: Re: Clipping and Renaming wavesink output file
Date: Tue, 2 Jan 2024 04:50:41 -0500

You wouldn't replace the file sink. Just call

  wavefile_sink.open(new_file_name)

which will also automatically close the old file for you.

Instead of using a work function to count items, add a separate timer thread to the python code that calls open() every 5 mins. Much simpler.

On Mon, Jan 1, 2024 at 11:44 PM Sreejith RK Nair <sreejithrknair143@gmail.com> wrote:
Hi, 
I have created a FM receiver using GNU and the output is fed to an audio sink to listen live and to a wavefile sink to record. There was no option to edit the recording time in GUI, so I edited the python code to record and rename the file every 5 mins. But the problem is only the first file has data and other files are created but with no data.The code i've written for this as follows:
 def create_new_file(self):
        current_time = datetime.datetime.now()
        elapsed_time = current_time - self.start_time
        if elapsed_time.total_seconds() >= REC_TIME_SEC:
            self.blocks_wavfile_sink_0.close()
            filename = 'E:\\Record\\{}.mp3'.format(current_time.strftime("%Y%m%d_%H%M%S"))
            self.blocks_wavfile_sink_0 = blocks.wavfile_sink(filename, 1, 48000, 8)
            self.start_time = current_time
           
    def check_and_create_file(self):
        current_time = datetime.datetime.now()
        elapsed_time = current_time - self.start_time
        if elapsed_time.total_seconds() >= REC_TIME_SEC:
            self.create_new_file()
           
    def work(self, input_items, output_items):
        current_time = datetime.datetime.now()
        elapsed_time = current_time - self.start_time
        self.total_items_written+=len(output_items[0])
        # Call create_new_file multiple times if enough time has elapsed
        if elapsed_time.total_seconds() >= REC_TIME_SEC:
            self.create_new_file()
            current_time = datetime.datetime.now()
            elapsed_time = current_time - self.start_time
             return len(output_items[0])
Thank you in advance..

reply via email to

[Prev in Thread] Current Thread [Next in Thread]