Merge branch 'master' of git.xpub.nl:/var/www/git.xpub.nl/repos/OuNoPo-make

master
Alice 7 years ago
commit 714562bb0c

BIN
.DS_Store vendored

Binary file not shown.

@ -32,6 +32,7 @@ clean: ## removes output (target) files
dirs: ## create the dirs in working dir
@-mkdir -p images/
@-mkdir -p output/
@-mkdir -p ocr/
@echo $(color_r)'Directories made': images/ output/
@ -60,7 +61,7 @@ output/tagged-words.txt: ocr/output.txt ## Analyzes OCR'ed text using a Part of
# >>> import nltk
# >>> nltk.download('averaged_perceptron_tagger')
output/chatbot.txt: ocr/output.txt ## DESCRIBE WHAT IT DOES. Dependencies: python3's chatterbot
output/chatbot.txt: ocr/output.txt ## Comments a text with a simple chatbot. Dependencies: python3's chatterbot
cat $< | python3 src/textbotconversation.py $(@)
@ -85,7 +86,6 @@ tts: output/chatbot.txt ocr/output.txt ## text to speech. Dependencies: espea
@echo $(color_w)
cat $? | espeak
ttstt: ocr/output.txt##text to speech, speech to text
cat $< | espeak -s 140 -v f2 --stdout > sound.wav
ttssr-human-only: ocr/output.txt ## Loop: text to speech-speech recognition. Dependencies: espeak, pocketsphinx
bash src/ttssr-loop-human-only.sh ocr/output.txt

@ -0,0 +1,92 @@
#!/usr/bin/env python3
import speech_recognition as sr
import sys
from termcolor import cprint, colored
# obtain path to "english.wav" in the same folder as this script
from os import path
import random
a1 = sys.argv[1] #same as $1 so when you run python3 audio_transcribe.py FOO ... argv[1] is FOO
# print ("transcribing", a1, file=sys.stderr)
AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), a1) # before it was english.wav
# AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "french.aiff")
# AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "chinese.flac")
# print (AUDIO_FILE)
# use the audio file as the audio source
r = sr.Recognizer()
with sr.AudioFile(AUDIO_FILE) as source:
audio = r.record(source) # read the entire audio file
color = ["white", "yellow"]
on_color = ["on_red", "on_magenta", "on_blue", "on_grey"]
# recognize speech using Sphinx
try:
cprint( r.recognize_sphinx(audio), random.choice(color), random.choice(on_color))
# print( r.recognize_sphinx(audio))
except sr.UnknownValueError:
print("uknown")
except sr.RequestError as e:
print("Sphinx error; {0}".format(e))
# sleep (1)
# # recognize speech using Google Speech Recognition
# try:
# # for testing purposes, we're just using the default API key
# # to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
# # instead of `r.recognize_google(audio)`
# print("Google Speech Recognition thinks you said " + r.recognize_google(audio))
# except sr.UnknownValueError:
# print("Google Speech Recognition could not understand audio")
# except sr.RequestError as e:
# print("Could not request results from Google Speech Recognition service; {0}".format(e))
# # recognize speech using Google Cloud Speech
# GOOGLE_CLOUD_SPEECH_CREDENTIALS = r"""INSERT THE CONTENTS OF THE GOOGLE CLOUD SPEECH JSON CREDENTIALS FILE HERE"""
# try:
# print("Google Cloud Speech thinks you said " + r.recognize_google_cloud(audio, credentials_json=GOOGLE_CLOUD_SPEECH_CREDENTIALS))
# except sr.UnknownValueError:
# print("Google Cloud Speech could not understand audio")
# except sr.RequestError as e:
# print("Could not request results from Google Cloud Speech service; {0}".format(e))
# # recognize speech using Wit.ai
# WIT_AI_KEY = "INSERT WIT.AI API KEY HERE" # Wit.ai keys are 32-character uppercase alphanumeric strings
# try:
# print("Wit.ai thinks you said " + r.recognize_wit(audio, key=WIT_AI_KEY))
# except sr.UnknownValueError:
# print("Wit.ai could not understand audio")
# except sr.RequestError as e:
# print("Could not request results from Wit.ai service; {0}".format(e))
# # recognize speech using Microsoft Bing Voice Recognition
# BING_KEY = "INSERT BING API KEY HERE" # Microsoft Bing Voice Recognition API keys 32-character lowercase hexadecimal strings
# try:
# print("Microsoft Bing Voice Recognition thinks you said " + r.recognize_bing(audio, key=BING_KEY))
# except sr.UnknownValueError:
# print("Microsoft Bing Voice Recognition could not understand audio")
# except sr.RequestError as e:
# print("Could not request results from Microsoft Bing Voice Recognition service; {0}".format(e))
# # recognize speech using Houndify
# HOUNDIFY_CLIENT_ID = "INSERT HOUNDIFY CLIENT ID HERE" # Houndify client IDs are Base64-encoded strings
# HOUNDIFY_CLIENT_KEY = "INSERT HOUNDIFY CLIENT KEY HERE" # Houndify client keys are Base64-encoded strings
# try:
# print("Houndify thinks you said " + r.recognize_houndify(audio, client_id=HOUNDIFY_CLIENT_ID, client_key=HOUNDIFY_CLIENT_KEY))
# except sr.UnknownValueError:
# print("Houndify could not understand audio")
# except sr.RequestError as e:
# print("Could not request results from Houndify service; {0}".format(e))
# # recognize speech using IBM Speech to Text
# IBM_USERNAME = "INSERT IBM SPEECH TO TEXT USERNAME HERE" # IBM Speech to Text usernames are strings of the form XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
# IBM_PASSWORD = "INSERT IBM SPEECH TO TEXT PASSWORD HERE" # IBM Speech to Text passwords are mixed-case alphanumeric strings
# try:
# print("IBM Speech to Text thinks you said " + r.recognize_ibm(audio, username=IBM_USERNAME, password=IBM_PASSWORD))
# except sr.UnknownValueError:
# print("IBM Speech to Text could not understand audio")
# except sr.RequestError as e:
# print("Could not request results from IBM Speech to Text service; {0}".format(e))

@ -0,0 +1,18 @@
#!/bin/bash
i=0;
#cp $1 output/input0.txt
echo "Read every new sentence out loud!"
head -n 1 $1 > output/input0.txt
while [[ $i -le 10 ]]
do echo $i
cat output/input$i.txt
python3 src/write_audio.py src/sound$i.wav 2> /dev/null
play src/sound$i.wav repeat 5 2> /dev/null & #in the background the sound, without it all the sounds play one by one//2 is stderr
python3 src/audio_transcribe.py sound$i.wav > output/input$((i+1)).txt 2> /dev/null
sleep
(( i++ ))
done
today=$(date +%Y-%m-%d);
mkdir -p "output/ttssr.$today"
mv -v output/input* output/ttssr.$today;
mv -v src/sound* output/ttssr.$today;

@ -1,71 +1,82 @@
import nltk
from sys import stdin, stdout
# Step 1: define input and set up a list
# Define input
input = stdin.read()
taggedwordlist = []
string = input
words = nltk.word_tokenize(string)
taggedwordlist = nltk.pos_tag(words)
for word, pos in nltk.pos_tag(words):
# FILTER FUNCTIONS
# This function cuts a string into words. Then runs a POS tagger for each word. Returns a list with tags
def postagger(string):
words = nltk.word_tokenize(string)
taggedwordlist = nltk.pos_tag(words)
# print('{0} is a {1}'.format(word,pos)) # Command out to print the analysis step
for word, pos in nltk.pos_tag(words):
taggedwordlist = nltk.pos_tag(words)
#print('{0} is a {1}'.format(word,pos)) # Comment out to print the analysis step
taglist = [ pos for word,pos in taggedwordlist ]
#print(taglist)
return taglist;
taglist = [ pos for word,pos in taggedwordlist ]
# This function changes the tags to readable equivalents (NNP to noun for example)
def postagger_readable(list):
readabletaglist = []
#print(taglist)
for tag in list:
if tag in {"NNP","NNS","NN","NNPS"}:
readabletag = 'noun'
elif tag in {'VB','VBD','VBG','VBN','VBP','VBZ'}:
readabletag = 'verb'
elif tag in {'RB','RBR','RBS','WRB'}:
readabletag = 'adverb'
elif tag in {'PRP','PRP$'}:
readabletag = 'pronoun'
elif tag in {'JJ','JJR','JJS'}:
readabletag = 'adjective'
elif tag == 'IN':
readabletag = 'preposition'
elif tag == 'WDT':
readabletag = 'determiner'
elif tag in {'WP','WP$'}:
readabletag = 'pronoun'
elif tag == 'UH':
readabletag = 'interjection'
elif tag == 'POS':
readabletag = 'possesive ending'
elif tag == 'SYM':
readabletag = 'symbol'
elif tag == 'EX':
readabletag = 'existential there'
elif tag == 'DT':
readabletag = 'determiner'
elif tag == 'MD':
readabletag = 'modal'
elif tag == 'LS':
readabletag = 'list item marker'
elif tag == 'FW':
readabletag = 'foreign word'
elif tag == 'CC':
readabletag = 'coordinating conjunction '
elif tag == 'CD':
readabletag = 'cardinal number'
elif tag == 'TO':
readabletag = 'to'
elif tag == '.':
readabletag = 'line ending'
elif tag == ',':
readabletag = 'comma'
else:
readabletag = tag
readabletaglist = []
readabletaglist.append(readabletag)
return readabletaglist;
for tag in taglist:
if tag in {"NNP","NNS","NN","NNPS"}:
readabletag = 'noun'
elif tag in {'VB','VBD','VBG','VBN','VBP','VBZ'}:
readabletag = 'verb'
elif tag in {'RB','RBR','RBS','WRB'}:
readabletag = 'adverb'
elif tag in {'PRP','PRP$'}:
readabletag = 'pronoun'
elif tag in {'JJ','JJR','JJS'}:
readabletag = 'adjective'
elif tag == 'IN':
readabletag = 'preposition'
elif tag == 'WDT':
readabletag = 'determiner'
elif tag in {'WP','WP$'}:
readabletag = 'pronoun'
elif tag == 'UH':
readabletag = 'interjection'
elif tag == 'POS':
readabletag = 'possesive ending'
elif tag == 'SYM':
readabletag = 'symbol'
elif tag == 'EX':
readabletag = 'existential there'
elif tag == 'DT':
readabletag = 'determiner'
elif tag == 'MD':
readabletag = 'modal'
elif tag == 'LS':
readabletag = 'list item marker'
elif tag == 'FW':
readabletag = 'foreign word'
elif tag == 'CC':
readabletag = 'coordinating conjunction '
elif tag == 'CD':
readabletag = 'cardinal number'
elif tag == 'TO':
readabletag = 'to'
elif tag == '.':
readabletag = 'line ending'
elif tag == ',':
readabletag = 'comma'
else:
readabletag = tag
readabletaglist.append(readabletag)
# This function creates the output
def main():
taglist = postagger(input)
readabletaglist = postagger_readable(taglist)
stdout.write(' '.join(readabletaglist))
stdout.write('\n')
stdout.write(' '.join(readabletaglist))
main()

@ -0,0 +1,25 @@
#!/usr/bin/env python3
# https://github.com/Uberi/speech_recognition/blob/master/examples/write_audio.py
# NOTE: this example requires PyAudio because it uses the Microphone class
import speech_recognition as sr
import sys
from time import sleep
a1 = sys.argv[1]
# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
# print("Read every new sentence out loud!")
audio = r.listen(source)
# sleep (1)
#
# # write audio to a RAW file
# with open("microphone-results.raw", "wb") as f:
# f.write(audio.get_raw_data())
# write audio to a WAV file
with open(a1, "wb") as f:
f.write(audio.get_wav_data())
Loading…
Cancel
Save