Skip to content

Commit b13116e

Browse files
authored
Add files via upload
1 parent 67d695e commit b13116e

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

script/detect_voice_main.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from voice_detect import Voice_Detect_Helper
2+
3+
def using_audio_to_talk(file_name = 'test.wav'):
4+
from recording_voice import Recording_Helper
5+
recorder = Recording_Helper(file_name=file_name)
6+
voice_detecter = Voice_Detect_Helper(file_path=file_name)
7+
recorder.recording_voice()
8+
voice_detecter.detect_voice()
9+
# you can get result from voice_detecter.result
10+
11+
def using_detecter_to_talk(file_name = 'test.wav'):
12+
voice_detecter = Voice_Detect_Helper(file_path=file_name)
13+
voice_detecter.listener()
14+
15+
if __name__ == '__main__':
16+
# method 1 using pyaudio to record
17+
# using_audio_to_talk()
18+
19+
# method 2 using speech_recognition to record
20+
using_detecter_to_talk()

script/process_order.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import pandas as pd
2+
import re
3+
def load_xlsx(file_name = 'menu.xlsx'):
4+
xls = pd.ExcelFile(file_name)
5+
df = xls.parse(xls.sheet_names[0])
6+
df = df.T
7+
# print(df)
8+
# print(df.to_dict())
9+
return df.to_dict()
10+
11+
def write_xlsx(file_name = 'menu.xlsx'):
12+
menu = {
13+
"item":["滷肉飯","豆花", "燒肉", "雞腿"],
14+
"price":[1, 2, 3, 4],
15+
}
16+
df = pd.DataFrame(data=menu)
17+
# df = (df.T)
18+
# print (df)
19+
df.to_excel(file_name)
20+
21+
def process_data_to_menu(data_dict:dict):
22+
menu_dict = dict()
23+
for key in data_dict:
24+
menu_dict[data_dict[key]['item']]=data_dict[key]['price']
25+
# print(menu_dict)
26+
return menu_dict
27+
28+
def process_price_with_order(menu_dict, order):
29+
# format is 多少個什麼和多少個什麼
30+
order = re.split('和|個', order)
31+
32+
# using stack to process item and amount
33+
price_dict = dict()
34+
top = None
35+
for item in order:
36+
if item.isdigit():
37+
if top == None:
38+
top = item
39+
else:
40+
price_dict[top] = {'amount':item, 'price':None}
41+
top = None
42+
else:
43+
if top == None:
44+
top = item
45+
else:
46+
price_dict[item] = {'amount':int(top), 'price':None}
47+
top = None
48+
49+
total = 0
50+
for item in price_dict:
51+
if item in menu_dict:
52+
price_dict[item]['price'] = price_dict[item]['amount'] * menu_dict[item]
53+
total += price_dict[item]['price']
54+
55+
print(menu_dict)
56+
print(price_dict)
57+
58+
# write_xlsx()
59+
data_dict = load_xlsx()
60+
menu_dict = process_data_to_menu(data_dict)
61+
process_price_with_order(menu_dict, '100個火腿和7000個蛋糕')

0 commit comments

Comments
 (0)