diff --git a/fileParse.py b/fileParse.py new file mode 100644 index 0000000000000000000000000000000000000000..4e41bcb1dd11f1b3951d428db740bad7c9801bd8 --- /dev/null +++ b/fileParse.py @@ -0,0 +1,39 @@ +from os import listdir, unlink +from os.path import isfile, join +import re +import numpy as np + +class FileParse: + def __init__(self,folderPath): + self.folderPath = folderPath + + def fileCount(self): + return len(listdir(self.folderPath)) + + def read(self): + file_list = listdir(self.folderPath) + data = "" + + for i, file in enumerate(file_list): + file_path = join(self.folderPath, file) + if i==(len(file_list)-1): + f = open(file_path, "r") + data = f.read() + try: + unlink(file_path) + except Exception as e: + print("failed to delete") + + result = [] + samples = data.splitlines() + for i, sample in enumerate(samples): + result.append([]) + s = sample.split(',') + for j, a in enumerate(s): + result[i].append(a) + + return result + +if __name__ == "__main__": + fp = FileParse("./test") + print(fp.read()) \ No newline at end of file diff --git a/team.py b/team.py new file mode 100644 index 0000000000000000000000000000000000000000..7bb70743abe11215c2ab4ff314006c9592c13e97 --- /dev/null +++ b/team.py @@ -0,0 +1,45 @@ +from audioPlayer import pyaudioPlayer +from signalGenerator import sineGenerator +from distance2Frequency import MaxMinConverter, derivativeConverter +from numberToSpeech import NumberToSpeech +import numpy as np +import time +from fileParse import FileParse + +duration = 0.1 +sleepDuration = 0.1 +speechDuration = 2.0 +volume = 0.75 +fs = 44100 + +flc = MaxMinConverter(10,300,220,880) +fdc = derivativeConverter(2,200,110,220,440,880) +tts = NumberToSpeech() +player = pyaudioPlayer(fs) +sg = sineGenerator(fs) +fp = FileParse("./test") +player.play() + +if(fp.fileCount()>0): + try: + datas = fp.read() + for data in datas: + print(data) + distance = int(data[1]) + mode = data[0] + if mode =='0' or mode =='1': + frequency = 0 + if(mode=='0'): + frequency = flc.convert(distance) + elif (mode=='1'): + frequency = fdc.convert(distance) + signal = sg.generate(frequency,volume, duration) + player.appendBuffer(signal) + time.sleep(sleepDuration) + if mode == '2': + tts.say(distance) + time.sleep(speechDuration) + if mode == '3': + print("not made") + except KeyboardInterrupt: # Ctrl+C + del player diff --git a/test/testData.txt b/test/testData.txt new file mode 100644 index 0000000000000000000000000000000000000000..7e6de070f5f886cb0220bb2149acc8ad4b62d31a --- /dev/null +++ b/test/testData.txt @@ -0,0 +1,122 @@ +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +2,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,100,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +0,200,0 +2,100,0 \ No newline at end of file