Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cutting out silence from the soundfiles after each character to make "--sm, --silencemorse" work for 0.1-1s #49

Open
heppstar opened this issue Feb 11, 2024 · 2 comments

Comments

@heppstar
Copy link

Hi,

I learned to play a game called "beat the computer". The computer plays a character and I try to say the character before the computer does. I narrow the time down to about 250ms between the computer plays the characters and I speaks the character .

However, It is not possible to set the time to 250ms with the original render.pl because the soundfiles from AWS include a silence. I have solved it by cutting the end of the soundfiles in render.pl like this:

             unlink "$output_directory/sentence-lower-volume-$speed.mp3" if (-f "$output_directory/sentence-lower-volume-$speed.mp3");
              print "---- move($output_directory/sentence-lower-volume-$speed-resampled.mp3, $cached_filename)\n";
              #move("$output_directory/sentence-lower-volume-$speed-resampled.mp3", $cached_filename);
	  my $temp_filename = "$output_directory/sentence-lower-volume-$speed-resampled-temp.mp3";
	  move("$output_directory/sentence-lower-volume-$speed-resampled.mp3", $temp_filename);

	  #STARTS HERE
	  
          #Get the total length of the soundfiles with ffprobe
	  my $ffprobe_cmd = "ffprobe -i $temp_filename -show_entries format=duration -v quiet -of csv=\"p=0\"";
	  my $duration = `$ffprobe_cmd`;

	  # Trim the last 350ms off the end of the file with ffmpeg
	  my $trim_cmd = "ffmpeg -i $temp_filename -ss 0 -t " . ($duration - 0.35) . " -c copy $cached_filename";
	  system($trim_cmd) == 0 or die "ERROR: $trim_cmd failed, $!\n";

          #ENDS HERE
              
	  unlink $temp_filename; # Radera temporärfilen
              unlink "$output_directory/sentence-${speed}0000.mp3";
            }

            # generate repeat section if it is different than the sentence
            if (!$no_repeat_morse && $word_limit == -1 && ($repeat_part ne $sentence_part || ($character_multiplier ne "1" && $standard_speed_repeat != 0))
                && (!-f $cached_repeat_filename)) {
              open(my $fh_repeat, '>', "$output_directory/sentence-repeat.txt");
              print $fh_repeat "$repeat_part\n";
              close $fh_repeat;

              my $ebookCmdBase_for_repeat = $ebookCmdBase;
              if($character_multiplier ne "1" && $standard_speed_repeat != 0) {
                $ebookCmdBase_for_repeat =~ s/-m \d+//;

This it not a good solution because I set a fixed time of 350ms to cut and I noticed the the silence length after the soundfiles differ depending on what WPM is used. I am not a programmer, but could it be fixed in a better way? That would be very nice! :)

@heppstar heppstar changed the title Cutting out silence from the soundfiles after each character to make "--sm, --silencemorse" work for lower the 0.1-1s Cutting out silence from the soundfiles after each character to make "--sm, --silencemorse" work for 0.1-1s Feb 11, 2024
@zoglmannk
Copy link
Owner

Let me think about this. Probably... A better way of doing this is by analyzing the audio file for silence and using that info to truncate the file.

@zoglmannk
Copy link
Owner

@heppstar Take a look at this pull request — #52 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants