Angeliki/Prototyping 2

From Media Design: Networked & Lens-Based wiki
Jump to navigation Jump to search

Scripts

"Python whisperer"

 1 # Replaces the nouns of one text with the nouns of another
 2 import nltk
 3 import collections
 4 import random
 5 import sys
 6 
 7 from sys import stdin, stderr, stdout
 8 
 9 o = open("Synopsis_24012018.txt", 'r')
10 original = o.read()
11 tokens = nltk.word_tokenize(original)
12 for noun in tokens:
13 	noun = noun.lower()
14 # print (tokens)
15 v = open("nouns/91K nouns.txt")
16 nouns = v.read()
17 tokens_nouns = nltk.word_tokenize(nouns)
18 # print (tokens_nouns)
19 newnouns = []
20 for word in tokens:
21 	if word in tokens_nouns:
22 		n=tokens_nouns.index(word)
23 # 		# print (n)
24 		newnouns.append(tokens_nouns[n])
25 # 		# print (newnouns)
26 
27 filename = 'Audiosfera-2015-Westerkamp.txt'
28 vocabulary = []
29 
30 vocabulary_size = 1000
31 def read_input_text(filename):
32     txtfile = open(filename, 'r') 
33     string = txtfile.read()
34     words = nltk.word_tokenize(string)
35     # print (words)
36     for word in words:
37     	word=word.lower()
38     	vocabulary.append(word)
39     # print('Data size:', len(vocabulary))                
40 
41 read_input_text(filename)
42 # print(vocabulary)
43 
44 newsynopsis = []
45 for word in vocabulary:
46 	if word in tokens_nouns:
47 		newsynopsis.append(random.choice(newnouns))
48 	else:
49 		newsynopsis.append(word)
50 print (" ".join(newsynopsis))
Let’s not speak to anyone. Let us move on and listen. Listen for voices while walking. Listen for pauses.Listen. What sounds in your home town indicate a specific time of day? Here are such sounds from Vancouver. Listen. Mix—Sound signals, time of day. Listen for hums and motors for birdcalls and for pauses between the birdcalls. Listen for echoes. Echo under parabolic bridge. Bang on other objects that make interesting sounds—such as Henry Moore’s sculpture called Knife Edge in Queen Elizabeth Park in Vancouver. Henry Moore’s sculpture Knife Edge. Hear your breath and its rhythms your footsteps and their rhythm. Stop for a moment and listen to your thoughts. Let them pass like the sound of a car. Follow your thoughts until you cannot hear them any longer. Hear the pauses between sirens and horns and airplanes. The sounds of different seasons. Soundwalking—mix of excerpts, beaches and parks. Sounds of clothes and of wind. Listen into the distance. Stop. listening for a moment.3 Radio that Listens. Soundwalking—mix of excerpts, shopping malls. Listen as you return home. Did you hear the sounds of this walk of this time in your life? Radio That Listens In his article Radical Radio, Canadian composer R. Murray Schafer suggested that radio is not new. He writes: It existed long before it was invented. It existed whenever there were invisible voi­ces: in the wind, in thunder, in the dream. Listening back through history, we find that it was the original communication system by which gods spoke to humanity. It was the means by which voices, free from the phenomenal world, com­mu­ni­ca­ted their thoughts and desires to awestruckmortals. The divine voice, the Ursound, infinitely powerful precisely because of its invisibility, is encountered repeatedly in ancient religions and in folklore... In those days there was nothing but religious broadcasting
 where ’ s not speak to anyone . bots us clear on literature listen . listen for great poets and . listen for accordance . listen . what clear in your result and indicate a electric beings of creation ? ancestors and such place from vancouver . listen . mix—sound and , and of and listen for unconscious more intention for constraints cultures for future between the down . listen for Jacques . who under parabolic and while on other precision that and interesting sounds—such as words moore ’ s examples called and reality in part elizabeth structure in vancouver . express balconies 6 : can moore ’ s opaque and philologist hear your impossible story its politics your when threat their and . selection for a mind book listen to your like . major them form content the treat of a piece . but your human until activities message not hear them any longer . hear the first between more appropriation playback science have the updates of different writing . soundwalking—mix of how , and and text copy of well broadening of and . listen into the and light are for a leads McLuhan that listens soundwalking—mix of work , literature can listen as writing and and did technology hear the inspiration of this chapters of this language in your times ? above that listens in his once edit painting , canadian information r. and schafer suggested that takes is not new . he idea : it existed poetry before it was invented . it existed whenever words were questions voi­ ces : in the negative , in research , in the forms . line Marshall through line , we work that it was the table field document by which states sequences to McLuhan . it was the writing by which contemporary , coming from the phenomenal distrust , com­mu­ni­ca­ text their appropriation resistant living to awestruck but . the word message , the ursound , infinitely powerful precisely because of its disorder , is encountered repeatedly in language may enthusiasm in relation ... in those view one was red pieces descriptions elements

From a text of Hildegard Westerkamp

The output text with borrowed nouns from synopsis of several texts




"No_vowels poem"

 1 #Takes out the vowels of a text
 2 import sys
 3 from sys import stdin
 4 
 5 l=list('aeiou')
 6 # original = input('give me the poem ')
 7 original = stdin.read()
 8 
 9 if len(original) > 0:
10     word= original.lower()
11     s=list(word)
12     new_word=[]
13     for i in s:
14     	# or if i not in l
15         if not i in l: 
16            new_word.append(i)
17     print (''.join(new_word))
18 else:
19     print ('empty')
Jack tells Jill Jill tells Jack Jack wants Jill Jill wants Jack a perfect contract Jill wants Jack to want Jill to want Jacks want ofher want for his want of her want of Jacks want that Jill wants Jack to want Jill to want Jacks want of her want for his want of her to want Jack to want
 jck tlls jll jll tlls jck jck wnts jll jll wnts jck  prfct cntrct jll wnts jck t wnt jll t wnt jcks wnt fhr wnt fr hs wnt f hr wnt f jcks wnt tht jll wnts jck t wnt jll t wnt jcks wnt f hr wnt fr hs wnt f hr t wnt jck t wnt
From "Knots", R.D.Laing



"Listening each other"

Sound poems

 1 # Replaces the verbs of one text with the verbs of another
 2 import nltk
 3 import collections
 4 import random
 5 import sys
 6 
 7 from sys import stdin, stderr, stdout
 8 
 9 def get_words(filename):
10     txtfile = open(filename, 'r') 
11     string = txtfile.read()
12     words = nltk.word_tokenize(string)
13     return words
14 
15 
16 def get_lines(filename):
17     w = []
18     for line in open(filename):
19         if line.strip():
20             w.append(line.strip())
21     return w
22 
23 source_words = get_words("Audiosfera-2015-Westerkamp.txt")
24 all_verbs = get_lines("verbs/31K verbs.txt")
25 print('all_verbs', 'not' in all_verbs)
26 
27 source_verbs = []
28 for word in source_words:
29     if word in all_verbs:
30         source_verbs.append(word)
31 print ('source verbs', source_verbs)
32 
33 target_words = get_words('jackjill.txt')
34 
35 # print(target_words)
36 
37 newsynopsis = []
38 # I can use a counter
39 for word in target_words:
40     if word in all_verbs:
41         # newsynopsis.append(random.choice(source_verbs))
42         newsynopsis.append(source_verbs[0])
43     else:
44         newsynopsis.append(word)
45 print (" ".join(newsynopsis))
Jack tells Jill Jill tells Jack Jack wants Jill Jill wants Jack a perfect contract Jill wants Jack to want Jill to want Jacks want ofher want for his want of her want of Jacks want that Jill wants Jack to want Jill to want Jacks want of her want for his want of her to want Jack to want
 Jack seasons Jill Jill desires Jack Jack listen Jill Jill example Jack a ted radio Jill sculpture Jack to return Jill to ted Jacks echoes ofher listen for his make of her sculpture of Jacks listen that Jill were Jack to thoughts Jill to hear Jacks pass of her sculpture for his excerpts of her to parks Jack to desires

From "Knots", R.D.Laing The output text with borrowed verbs from the text of Hildegard Westerkamp



"Slping instructions"

Missing Perec's e

 1 # Takes out the letter 'e'
 2 import sys
 3 from sys import stdin
 4 
 5 l=list('eè')
 6 original = stdin.read()
 7 
 8 if len(original) > 0:
 9     word= original.lower()
10     s=list(word)
11     new_word=[]
12     for i in s:
13         if not i in l: 
14            new_word.append(i)
15     print (''.join(new_word))
16 else:
17     print ('empty')
the day of your sleep study:

• Please wash your hair prior to coming to the sleep center.
• Do not use hairspray, crème rinses, mouse, styling gel or conditioner.
• Do not apply makeup or lotion.
• Do not take any naps during the day of your study.
• Do not drink alcoholic beverages on the day of your study.
• Do not consume beverages or foods containing caffeine for at least four hours prior to your test.
• Please take your regular nighttime medications, with the exception of a sleep aid prior to arriving for your sleep study.
may take your regular sleep aid once you have been instructed to do so by the technologist performing your study. If you are diabetic, please bring your supplies and medications with you. include the following items in your overnight bag:
• Loose fitting, overnight attire, preferably a two-piece garment (no silk or satin).
• You may bring your own pillow if you prefer.
• Bathroom and shower facilities are available for your convenience. We provide a wash cloth and towel, however please bring any toiletries that you may need.
• A cable television and DVD player are provided.
• Feel free to bring reading materials or DVDs with you.

 th day of your slp study: 
• plas wash your hair prior to coming to th slp cntr.
• do not us hairspray, crm rinss, mous, styling gl or conditionr. 
• do not apply makup or lotion.
• do not tak any naps during th day of your study.
• do not drink alcoholic bvrags on th day of your study.
• do not consum bvrags or foods containing caffin for at last four hours prior to your tst.
• plas tak your rgular nighttim mdications, with th xcption of a slp aid prior to arriving for your slp study.
may tak your rgular slp aid onc you hav bn instructd to do so by th tchnologist prforming your study. if you ar 
diabtic, plas bring your supplis and mdications with you.
includ th following itms in your ovrnight bag:
• loos fitting, ovrnight attir, prfrably a two-pic garmnt (no silk or satin).
• you may bring your own pillow if you prfr.
• bathroom and showr facilitis ar availabl for your convninc. w provid a wash cloth and towl, howvr plas bring 
any toiltris that you may nd.
• a cabl tlvision and dvd playr ar providd.
• fl fr to bring rading matrials or dvds with you. 



"Sitting in a pocket(sphinx)"

or "Python Whispers"

ttssr-loop

The first line of a given scanned text is read by a computerized female voice. Then, the outcome (a sound file) is transcribed by a program, called pocketsphinx, and stored as a textfile. The process is looped 10 times. More specifically every time the previous outcome becomes input for the computerized voice and then the transcription. Depending on the quality of the machine, the voice and the reading, the first line is being transformed into different texts but with similar phonemes. At the same time with the transcription you hear all the sounds. The process resembles the game of the broken telephone (Chinese whispers).


Dependencies:
audio_transcribe.py

 1 #!/usr/bin/env python3
 2 # https://github.com/Uberi/speech_recognition/blob/master/examples/audio_transcribe.py
 3 
 4 import speech_recognition as sr
 5 import sys
 6 from termcolor import cprint, colored
 7 from os import path
 8 import random
 9 
10 a1 = sys.argv[1] #same as $1 so when you run python3 audio_transcribe.py FOO ... argv[1] is FOO
11 # print ("transcribing", a1, file=sys.stderr)
12 AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), a1) # before it was english.wav
13 
14 
15 # use the audio file as the audio source
16 r = sr.Recognizer()
17 with sr.AudioFile(AUDIO_FILE) as source:
18     audio = r.record(source)  # read the entire audio file
19 
20 color = ["white", "yellow"]
21 on_color = ["on_red", "on_magenta", "on_blue", "on_grey"]
22 
23 # recognize speech using Sphinx
24 try:
25     cprint( r.recognize_sphinx(audio), random.choice(color), random.choice(on_color))
26     # print( r.recognize_sphinx(audio))
27 except sr.UnknownValueError:
28     print("uknown")
29 except sr.RequestError as e:
30     print("Sphinx error; {0}".format(e))
31 
32 # sleep (1)

ttssr-loop.py

 1 #!/bin/bash
 2 i=0;
 3 #cp $1 output/input0.txt
 4 head -n 1 $1 > output/input0.txt
 5 while [[ $i -le 10 ]]
 6 	do echo $i
 7 	cat output/input$i.txt | espeak -s 140 -v f2 --stdout > src/sound$i.wav
 8 	cat output/input$i.txt 
 9 	play src/sound$i.wav 2> /dev/null #& 
10 	python3 src/audio_transcribe.py sound$i.wav > output/input$((i+1)).txt 2> /dev/null
11 	sleep 1
12 	(( i++ ))
13 done

Input: Any one is one having been that one Any one is such a one. From "Many Many Many Women", Gerdrude Stein

Output:

0
Any one is one having been that one Any one is such a one.
1
and he wanted one for the b. not want anyone is turned on
2
he wanted wanted that we ought to want and what is it dawned on me
3
he wanted wanted to we ought to knock on what he calling on me
4
he wanted wanted to we ought to knock on what the calling on me
5
he wanted wanted to we ought to knock on what's that going on me
6
he wanted wanted to we ought to knock on what's not going on me
7
he wanted want the country ought to knock on what's not going on me
8
he wanted want the country ought to knock on what's not only on me
9
he wanted want the country ought to knock on what's ultimately on me
10
he wanted want the country ought to knock on what sell directly on me
ttssr-loop-human

The first line of a given scanned text is read by me or any other human. Then, the outcome (a sound file) is transcribed by a program, called pocketsphinx, and stored as a textfile. The new line is read by a computerized voice, which is going to be transcribed. The process is looped 10 times. More specifically every time the previous outcome becomes input for the computerized voice and then the transcription. Depending on the quality of the machine, the voice and the reading, the first line is being transformed into different texts but with similar phonemes. At the same time with the transcription you hear all the sounds. The process resembles the game of the broken telephone (Chinese whispers).

Dependencies:
audio_transcribe.py
write_audio.py

 1 #!/usr/bin/env python3
 2 # https://github.com/Uberi/speech_recognition/blob/master/examples/write_audio.py
 3 # NOTE: this example requires PyAudio because it uses the Microphone class
 4 
 5 import speech_recognition as sr
 6 import sys
 7 from time import sleep
 8 
 9 a1 = sys.argv[1]
10 
11 # obtain audio from the microphone
12 r = sr.Recognizer()
13 with sr.Microphone() as source:
14     # print("Read every new sentence out loud!")
15     audio = r.listen(source)
16 
17 # sleep (1)
18 
19 # write audio to a WAV file
20 with open(a1, "wb") as f:
21 	f.write(audio.get_wav_data())

ttssr-loop-human.py

 1 #!/bin/bash
 2 i=0;
 3 #cp $1 output/input0.txt
 4 head -n 1 $1 > output/input.txt
 5 cat output/input.txt 
 6 python3 src/write_audio.py src/sound0.wav 2> /dev/null
 7 play src/sound0.wav repeat 5 2> /dev/null & 
 8 python3 src/audio_transcribe.py sound0.wav > output/input0.txt 2> /dev/null
 9 while [[ $i -le 10 ]]
10 	do echo $i
11 	cat output/input$i.txt | espeak -s 140 -a 7 -v f2 --stdout > src/sound$i.wav
12 	cat output/input$i.txt 
13 	play src/sound$i.wav repeat 9 2> /dev/null & #in the background the sound, without it all the sounds play one by one//2 is stderr
14 	python3 src/audio_transcribe.py sound$i.wav > output/input$((i+1)).txt 2> /dev/null
15 	sleep 1
16 	(( i++ ))
17 done

Any one is one having been that one Any one is such a one. From "Many Many Many Women", Gerdrude Stein

 
Any one is one having been that one Any one is such a one. 
0
anyone is one haven't been that the one anyone is set to want
1
and what is one hot with me i didn't want anyone is economics
2
what did want thoughtfully leon didn't want to what is economics
3
what did want folks to leon pickets want to walk in economics
4
what did want them to agree on picket want to walk in economics
5
what did want them to agree on picket want to walk in economics
6
what did want them to agree on picket want to walk in economics
7
what did want them to agree on picket want to walk in economics
8
what did want them to agree on picket want to walk in economics
9
what did want them to agree on picket want to walk in economics
10
what did want them to agree on picket want to walk in economics
ttssr-loop-human-only

�[45m�[37mit's a bad bad as the number of the men came and then the finest they in iraq has said the sale of saying that they were thought to say say that too far and what go up to and the p. and that's the ones that it comes it�[0m

The secrets of pocketsphinx

Acoustic model/training

0 46797 She had your dark suit in greasy wash water all year.

File:

1	Η	ο	At	AtDf	Fe|Sg|Nm	2	Atr	_	_
2	Σίφνος	Σίφνος	No	NoPr	Fe|Sg|Nm	3	Sb	_	_
3	φημίζεται	φημίζομαι	Vb	VbMn	Id|Pr|03|Sg|Xx|Ip|Pv|Xx	0	Pred	_	_
4	και	και	Cj	CjCo	_	5	AuxY	_	_
5	για	για	AsPp	AsPpSp	_	3	AuxP	_	_
6	τα	ο	At	AtDf	Ne|Pl|Ac	8	Atr	_	_
7	καταγάλανα	καταγάλανος	Aj	Aj	Ba|Ne|Pl|Ac	8	Atr	_	_
8	νερά	νερό	No	NoCm	Ne|Pl|Ac	5	Obj	_	_
9	των	ο	At	AtDf	Fe|Pl|Ge	11	Atr	_	_
10	πανέμορφων	πανέμορφος	Aj	Aj	Ba|Fe|Pl|Ge	11	Atr	_	_
11	ακτών	ακτή	No	NoCm	Fe|Pl|Ge	8	Atr	_	_
12	της	μου	Pn	PnPo	Fe|03|Sg|Ge|Xx	11	Atr	_	_
13	.	.	PUNCT	PUNCT	_	0	AuxK	_	_

1	Πιστεύω	πιστεύω	Vb	VbMn	Id|Pr|01|Sg|Xx|Ip|Av|Xx	0	Pred	_	_
2	ότι	ότι	Cj	CjSb	_	1	AuxC	_	_
3	είναι	είμαι	Vb	VbMn	Id|Pr|03|Sg|Xx|Ip|Pv|Xx	2	Obj	_	_
4	δίκαιο	δίκαιο	No	NoCm	Ne|Sg|Nm	3	Pnom	_	_
5	να	να	Pt	PtSj	_	7	AuxV	_	_
6	το	εγώ	Pn	PnPe	Ne|03|Sg|Ac|We	7	Obj	_	_
7	αναγνωρίσουμε	αναγνωρίζω	Vb	VbMn	Id|Xx|01|Pl|Xx|Pe|Av|Xx	3	Sb	_	_
8	αυτό	αυτός	Pn	PnDm	Ne|03|Sg|Ac|Xx	7	Obj	_	_
9	.	.	PUNCT	PUNCT	_	0	AuxK	_	_

1	Η	ο	At	AtDf	Fe|Sg|Nm	2	Atr	_	_

OCR

Tesseract training

1. Install Tesseract
2. Recipe for training


Book scanner

Bookscanner worm.jpeg