import spacy
from scipy.io.wavfile import read

scoreForClearness = 50/100
nlp = spacy.load("en_core_web_sm")


def clearnerssWords(text):
    doc = nlp(text)
    returnVal = ""
    for token in doc:
        count = len(token)
        if count > 12:
            returnVal += f"{token.text} - {count} letters: This is a too complicated word. It is better to use more simpler word."
    return {
        "message": returnVal,
        "score": scoreForClearness
    }


def clearnerssSentence(text):
    doc = nlp(text)
    returnVal = ""
    for sent in doc.sents:
        word_count = 0
        # print(sent.text)
        for words in sent:
            # print(words.text)
            word_count = word_count + 1
        if word_count > 10:
            # print(f'"{sent}" is a overcomplicated sentence. There are {word_count}  words in it.')
            returnVal += f'"{sent}" is a overcomplicated sentence. There are {word_count}  words in it.'
        # print(word_count)
    return {
        "message": returnVal,
        "score": scoreForClearness
    }


def clearnessReadAudioFile(filePath):
    # Read the Audiofile
    samplerate, data = read(filePath)
    # Frame rate for the Audio
    print(samplerate)

    # Duration of the audio in seconds.
    duration = len(data)/samplerate
    print("Duration of Audio in Seconds", duration)
    print("Duration of Audio in Minutes", duration/60)
    print(len(data))

