dotBATmanNO / PSPublish-PPTX-Speech

Publish your PowerPoint to video using Text-To-Speech and subtitles. Target Users: Conferences / LMS Content Publishers. Top use case: Translation
GNU General Public License v3.0
0 stars 0 forks source link

Create subtitle files to overlay videos made with text-to-speech #2

Open dotBATmanNO opened 4 years ago

dotBATmanNO commented 4 years ago

Create subtitle files to overlay videos made with text-to-speech

I propose the use of the SubRip subtitle (.SRT) format. https://www.3playmedia.com/2017/03/08/create-srt-file/

Example attached. Publish-PPTX-Speech_srt.txt

dotBATmanNO commented 4 years ago

WorkInProgress

Currently able to break input text in 32 char chunks, this is the recommended max of a subtitle line.

$Sentence = "This sentence is quite long, how can we break it up? And what if it is crazy long?"

$LineMax = 32
Function fnSplitLine
{
 # Based in part on trick found at
 # https://stackoverflow.com/questions/31663644/

 [CmdletBinding()]
    param(
      [String]$Message,
      [Int]$LineLength=32)

    $linewords = ($Message | Select-String " " -AllMatches).Matches.Index

    $diff = $linelength - $linewords[0]
    $min_index = 0
    for ($i = 1; $i -lt $linewords.count; $i++)
    {
      $new_diff = $linelength - $linewords[$i]

      if ($new_diff -lt $diff -and $new_diff -ge 0)
      {
        $diff = $new_diff
        $min_index = $i
      }

    }
    Return $LineWords[$min_index]
}

write-host "12345678901234567890123456789012"
While ($Sentence.Length -gt $LineMax)
{ 
  $LineLen = fnSplitLine -Message $Sentence -LineLength 32
  write-host $Sentence.SubString(0, $LineLen)
  $Sentence = $Sentence.SubString($LineLen + 1)
}
If ($Sentence.Length -gt 0) { Write-Host $Sentence }