Angeliki/Grad Scripts

From Media Design: Networked & Lens-Based wiki
Revision as of 16:55, 30 May 2019 by Angeliki (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

srttojs.py

Make subtitles 'linkable' for html

pip install pysrt
 1 import pysrt, argparse
 2 
 3 ap = argparse.ArgumentParser("srttojs")
 4 ap.add_argument("srt")
 5 args = ap.parse_args()
 6 
 7 srt= pysrt.open(args.srt)
 8 print("<div class='sub'>")
 9 for t in srt:
10     print ('<div><a data-start="{1}" href="#">{0}</a> {2}</div>'.format(t.start, t.start.ordinal/1000.0, t.text))
11 print ("</div>")

addmetadata.py

Add metadata to an audio file

pip install pydub
1 from pydub.utils import mediainfo
2 from pydub import AudioSegment
3 sound= AudioSegment.from_file("podcasts/podcast.20190501-1223-femalemale.mp3", format="mp3")
4 file=sound.export("podcasts/podcast.20190501-1223-femalemale-.mp3", tags={"title":"transformation for presence", "narrator":"angeliki", "topic":"female voice to male"})

metadatatohtml.py

Edit metadata for html preview

pip install pydub
 1 from pydub import AudioSegment
 2 from pydub.utils import mediainfo
 3 import pprint
 4 
 5 z = mediainfo("podcasts/3_podcast.mp3.mp3")
 6 
 7 # sound= AudioSegment.from_file("podcasts/3_podcast.mp3", format="mp3")
 8 # file=sound.export("out.mp3", tags={"podcaster":"lain"})
 9 # print (mediainfo("out.mp3"))
10 
11 
12 def dict_to_html(dd, level=0):
13     """
14     Convert dict to html using basic html tags
15     """
16     import simplejson
17     text = ''
18     for k, v in dd.items():
19         text += '<br>' + '&nbsp;'*(4*level) + '<b>%s</b>: %s' % (k, dict_to_html(v, level+1) if isinstance(v, dict) else (simplejson.dumps(v) if isinstance(v, list) else v))
20     return text
21 
22 def dict_to_html_ul(dd, level=0):
23     """
24     Convert dict to html using ul/li tags
25     """
26     import simplejson
27     text = '<ul>'
28     for k, v in dd.items():
29         text += '<li><b>%s</b>: %s</li>' % (k, dict_to_html_ul(v, level+1) if isinstance(v, dict) else (simplejson.dumps(v) if isinstance(v, list) else v))
30     text += '</ul>'
31     return text
32 
33 print (dict_to_html(z, level=0))


podcast

Make podcasts with one command that accesses microphone and soundcard

check: Command-line podcasts
 1 #!/bin/bash
 2 output=${1:-podcast}
 3 arecord -Dpulse_monitor -f cd ${output}_sc.wav &
 4 arecord -Dpulse -f cd ${output}_mic.wav 
 5 ffmpeg -i ${output}_mic.wav -i ${output}_sc.wav -filter_complex amerge -ac 2 -c:a libmp3lame -q:a 4 ${ou$
 6 
 7 today=$(date +%Y%m%d-%H%M);
 8 mkdir -p "podcast.$today" 
 9 mv podcast.$today podcasts/;
10 mv -v ${output}_sc.wav podcasts/podcast.$today/${output}_sc.$today.wav;
11 mv -v ${output}_mic.wav podcasts/podcast.$today/podcast_mic.$today.wav;
12 mv -v ${output}.mp3 podcasts/${output}.$today.mp3;

audiojs

femaletomale.sh

1 #!/bin/bash
2 today=$(date +%Y%m%d-%H%M);
3 output=${1:-distort}
4 arecord -Dpulse -f cd normal_$today.wav
5 rubberband -t 1.5 -p -5.5 normal_$today.wav ${output}_$today.wav
6 
7 mkdir -p "normal" 
8 mv -v normal_$today.wav normal/normal_$today.wav;

maletofemale.sh

 1 #!/bin/bash
 2 today=$(date +%Y%m%d-%H%M)
 3 output=${1:-distort}
 4 arecord -Dpulse -f cd normal_$today.wav
 5 rubberband -t 1.5 -p 3.0 normal_$today.wav ${output}_$today.wav
 6 
 7 mkdir -p "storage" 
 8 mv -v normal_$today.wav storage/
 9 ffmpeg -i ${output}_$today.wav -vn -ar 44100 -ac 2 -ab 192k -f mp3 ${output}_$today.mp3
10 mv -v ${output}_$today.wav storage/