0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

一行にまとめられたテキストを、改行情報ファイルを読みだして、その通りに切り分けて別のファイルとして書き出すPGM

0
Last updated at Posted at 2026-01-30

一行にまとめられたテキストを、改行情報ファイルを読みだして、その通りに切り分けて別のファイルとして書き出すPGMをpowershellで作成しました。

改行情報ファイルは以前のPGMを使って作成します.


このファイルとvoicevox等の声優情報を左右につなげることで、テキストを 渡さずにテキストを持っている方がいれば「改行情報」&「声優振り分け情報」 だけを渡して、読み上げ音声が作成できます。
左右ファイル結合PGM
$file1 = Get-Content "C:\path\to\file1.txt"
$file2 = Get-Content "C:\path\to\file2.txt"

for($i = 0; $i -lt $file1.Count; $i++) {
    # 2つのファイルをカンマで区切って結合
    ("{0},{1}" -f $file1[$i], $file2[$i]) | Add-Content "C:\path\to\combined.txt"
}

PGM内容

$StrArr = Get-Content "C:\一行にまとめられたテキストのファイルがあるパス\test2.txt" -Encoding utf8
$DivLenArr =  Get-Content "C:改行情報ファイルがあるパス\test20.txt" -Encoding utf8
$DivLenArr2 = $DivLenArr.Replace('(', '')
$DivLenArr2 = $DivLenArr2.Replace(')', '')
$DivLenArr2 = $DivLenArr2.Split(",")

$idx = 0;
$divLines = @();

write-host "aaa"
write-host $StrArr.Length
write-host "aaa"

foreach ($len1 in $DivLenArr2) {
 $endIdx = $idx + $len1
 if($endIdx -ne $idx){
     $divStr1 = $StrArr.Substring($idx, ($endIdx-$idx) );
     #Write-Host $divStr1
     #Write-Host $idx  ", " $endIdx
 }else{
    $divStr1 = ""
 }

 $divLines += $divStr1
 $idx = $endIdx;
}


$savePath = "C:\切り分けたテキストを保存するファイルのパス\test22.txt";

$divLines | Set-Content -Path $savePath -Encoding UTF8


0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?