Skip to content

Instantly share code, notes, and snippets.

@YamimakiReru
Created March 15, 2026 14:33
Show Gist options
  • Select an option

  • Save YamimakiReru/919763b91b47c03cdb5ec2914c1647a2 to your computer and use it in GitHub Desktop.

Select an option

Save YamimakiReru/919763b91b47c03cdb5ec2914c1647a2 to your computer and use it in GitHub Desktop.
Mozilla Common Voiceデータ抽出用スクリプト https://note.com/yamimaki_reru/n/n049fb1498365
#!/usr/bin/env python
# Common Voiceの各mp3を作業用フォルダにコピーするためのスクリプト
import os
import shutil
def main():
cur_dir = os.path.dirname(__file__)
dest_dir = 'C:\work\in\cv'
os.makedirs(dest_dir, exist_ok=True)
with open(os.path.join(cur_dir, 'to-copy.csv')) as f:
for line in f:
line = line.strip()
if 0 == len(line):
break
(dname, fname) = line.split(',')
shutil.copy(os.path.join(cur_dir, dname, fname),
os.path.join(dest_dir, fname))
if __name__ == '__main__':
main()
#!/usr/bin/env python
# Common Voiceの各mp3が入っているフォルダを探しCSVを吐き出すために書いたスクリプト
import os
def main():
file_dir_map = dict()
cur_dir = os.path.dirname(__file__)
with open(os.path.join(cur_dir, 'files.csv')) as f:
for line in f:
line = line.strip()
if 0 == len(line):
break
(fname, dname) = line.split(',')
file_dir_map[fname] = dname
buf = ''
with open(os.path.join(cur_dir, 'targets.csv')) as f:
for line in f:
line = line.strip()
if 0 == len(line):
break
buf += file_dir_map[line] + "\n"
with open(os.path.join(cur_dir, 'out-targets.csv'), mode='w') as f:
f.write(buf)
if __name__ == '__main__':
main()
#!/usr/bin/env python
# Common Voiceの「ファイル名,ディレクトリ名」のCSVを吐き出すために書いたスクリプト
import os
import math
def main():
buf = ''
dir_count = 0
cur_dir = os.path.dirname(__file__)
with open(os.path.join(cur_dir, 'files.csv'), mode='w') as f:
with os.scandir(cur_dir) as dir_it:
for dir_ent in dir_it:
if not dir_ent.is_dir():
continue
dir_count += 1
for file_ent in os.listdir(os.path.join(cur_dir, dir_ent)):
buf += f"{file_ent},{dir_ent.name}\n"
f.write(buf)
buf = ''
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment