예제 #1
0
def robot():

    # 先关闭监听,已解决麦克风占用问题

    detector.terminate()

    # 播放一个音效,以提示开始录音了

    os.system('mplayer conan.mp3')

    # 调用百度asr,录入文字
    rec.rec()
    input_text = baidu_voice.get_asr('rec_temp.wav')

    ####################################
    # 调用图灵机器人的接口,获得返回的值
    ####################################
    query = {
        "reqType": 0,
        "perception": {
            "inputText": {
                "text": input_text
            },
            "inputImage": {
                "url": "imageUrl"
            },
            "selfInfo": {
                "location": {
                    "city": "",
                    "province": "",
                    "street": ""
                }
            }
        },
        "userInfo": {
            "apiKey": "5456995947d44f999a3d89819c7da2df",
            "userId": "338867"
        }
    }

    url = 'http://openapi.tuling123.com/openapi/api/v2'

    r = requests.post(url, data=json.dumps(query))

    output = r.json()
    output_text = output.get('results')[0].get('values').get('text')

    #########################
    # 图灵机器人的请求结束
    #########################

    # 调用百度TTS,获得语音合成

    output_file = baidu_voice.get_tts(output_text)

    os.system('mplayer ' + output_file)

    return ()
예제 #2
0
def speech():
    global SC
    global SN
    while True:
        speak = rec.rec()
        if (speak == 0):
            continue
            str_length = 1
        elif (speak == 'Google' or speak == '谷歌'):
            os.system('mpv ./voice/saySomething.mp3')
            while True:
                speak = rec.rec()
                if (speak == 0):
                    pass
                elif (speak == 'OK'):
                    pyautogui.press('enter')
                    break
                elif speak == '刪除':
                    for x in range(str_length):
                        pyautogui.press('backspace')
                    break
                elif speak == '滾動':
                    if SC == 0:
                        SC = 1
                        os.system('mpv ./voice/scroll.mp3')
                    else:
                        SC = 0
                    break
                elif speak == '空格':
                    pyautogui.press('space')
                    str_length = str_length + 1
                    break
                elif speak == '控制' or speak == '同志':
                    #rec.t2speech("this is command mode")
                    os.system('mpv ./voice/controlMode.mp3')
                    command = rec.rec()
                    if (command == 0):
                        pass
                    else:
                        pyautogui.press(command.lower())
                    break
                elif speak == '遊戲':
                    if SN == 0:
                        os.system('mpv ./voice/play.mp3')
                        SN = 1
                    else:
                        SN = 0
                else:
                    pyautogui.click()
                    paste(speak)
                    str_length = len(str(speak))
                    break
예제 #3
0
def login(user,pwd,codelen=4):
    url = 'http://www.t5csol.cn/vip.asp'
    codeurl = 'http://www.t5csol.cn/Include/getcode.asp?a=232&b=232&c=232&d=255&e=0&f=65'
    posturl = 'http://www.t5csol.cn/vip.asp?action=login'
    req = requests.session()
    req.get(url)
    #print req.cookies
    image = req.get(codeurl).content
    with open('code.gif','wb') as f:
        f.write(image)
    code = rec('code.gif')
    if len(code) != codelen:
        return login(user,pwd)
    #print code
    #print req.cookies
    data = 'username=%s&password=%s&code=%s&imageField.x=25&imageField.y=11' % (user,pwd,code)
    #print data
    t = req.post(posturl,data=data).content
    if len(t) == 77:
        print pwd,'wrong'
    elif len(t) == 73:
        return login(user,pwd)
    else:
        print '********NOTICE********'
        print pwd
        print '********NOTICE********'
        raw_input()
        exit()
예제 #4
0
def main():
    #发送者默认设置
    FROM = '你的邮箱地址'
    password = "******"
    smtp_server = "smtp服务器地址"

    #根据语音提示输入音频,识别并返回结果
    speak.say('to.wav')
    start = rec.rec(10)
    speak.say('toe.wav')
    end = rec.rec(5).lower()
    TO = start + '@' + end + '.com'
    print(TO)  #由于不能识别特殊符号,所以就把接收邮箱内容分割输入
    speak.say('toname.wav')
    name = rec.rec(5)
    speak.say('tosub.wav')
    SUBJECT = rec.rec(5)
    speak.say('totext.wav')
    text = rec.rec(10)

    def _format_addr(s):
        # 这个函数的作用是把一个标头的用户名编码成utf-8格式的,如果不编码原标头中文用户名,用户名将无法被邮件解码
        name, addr = parseaddr(s)
        return formataddr((Header(name, "utf-8").encode(), addr))
        # Header().encode(splitchars=';, \t', maxlinelen=None, linesep='\n')
        # 功能:编码一个邮件标头,使之变成一个RFC兼容的格式

    # 接下来定义邮件本身的内容
    msg = MIMEMultipart()
    msg["From"] = _format_addr("CC <%s>" % FROM)
    msg["To"] = _format_addr("%s <%s>" % (name, TO))
    msg["Subject"] = Header(SUBJECT, "utf-8").encode()
    # 定义邮件正文
    msg.attach(MIMEText(text, "plain", "utf-8"))

    # 接下来定义发送文件
    try:
        server = smtplib.SMTP(smtp_server, 25)
        server.login(FROM, password)
        server.sendmail(FROM, [TO], msg.as_string())
        server.quit()
        speak.say('success.wav')
    except Exception, e:
        speak.say('faild.wav')
        print str(e)
예제 #5
0
def convolve(a, b):
    #a=np.array(a)
    #b=np.array(b)
    fa = np.fft.fft(a)
    fb = np.fft.fft(b)
    ab = np.fft.ifft(fa * fb)
    ii = np.arange(np.size(ab))
    jj, abnew = rec(ii, ab)
    return abnew
예제 #6
0
from rec import rec

rec("small.in", "small.out")
#rec("large.in", "large.out")
예제 #7
0
import appid
import time
import rec
from aip import AipSpeech

client = AipSpeech(appid.ID, appid.KEY, appid.SK)
file_name = str(time.time())
rec.rec(file_name)
with open(file_name, 'rb') as fp:
    file_context = fp.read()
res = client.asr(file_context, 'pcm', 16000, {
    'dev_pid': 1536,
})

print(res)
예제 #8
0
def ode_updater(
        update_stp, tot_time, save_stp, y, rindx, pindx, rstoi, pstoi, nreac,
        nprod, jac_stoi, njac, jac_den_indx, jac_indx, RO2_indx, H2Oi, temp,
        tempt, Pnow, light_stat, light_time, daytime, lat, lon, af_path,
        dayOfYear, photo_path, Jlen, con_infl_C, nrec_steps, dydt_vst, siz_str,
        num_sb, num_comp, seedi, seed_name, seedVr, core_diss, Psat, mfp,
        therm_sp, accom_coeff, y_mw, surfT, R_gas, NA, y_dens, x, Varr,
        act_coeff, Cw, kw, Cfactor, tf, light_ad, y_arr, y_rind,
        uni_y_rind, y_pind, uni_y_pind, reac_col, prod_col, rstoi_flat,
        pstoi_flat, rr_arr, rr_arr_p, rowvals, colptrs, wall_on, jac_wall_indx,
        jac_part_indx, Vbou, N_perbin, Vol0, rad0, np_sum, new_partr, nucv1,
        nucv2, nucv3, nuci, nuc_comp, nuc_ad, RH, RHt, coag_on, inflectDp,
        pwl_xpre, pwl_xpro, inflectk, chamR, McMurry_flag, p_char, e_field,
        injectt, inj_indx, Ct, pmode, pconc, pconct, mean_rad, lowsize,
        uppsize, std, rbou, const_infl_t, MV, rindx_aq, pindx_aq, rstoi_aq,
        pstoi_aq, nreac_aq, nprod_aq, jac_stoi_aq, njac_aq, jac_den_indx_aq,
        jac_indx_aq, y_arr_aq, y_rind_aq, uni_y_rind_aq, y_pind_aq,
        uni_y_pind_aq, reac_col_aq, prod_col_aq, rstoi_flat_aq, pstoi_flat_aq,
        rr_arr_aq, rr_arr_p_aq, eqn_num, partit_cutoff, diff_vol, DStar_org,
        corei, ser_H2O, C_p2w, sch_name, sav_nam, comp_namelist, dydt_trak,
        space_mode, rbou00, ub_rad_amp, indx_plot, comp0, inname, rel_SMILES,
        Psat_Pa_rec, OC, wat_hist, Pybel_objects):

    # inputs: ----------------------------------------------------
    # update_stp - interval at which to update integration
    #		constants (s)
    # tot_time - total time to simulate (s)
    # save_stp - frequency to save results (s)
    # y - initial component concentrations (molecules/cc/s)
    # rindx - index of reactants per equation
    # pindx - index of products per equation
    # nreac - number of reactants per equation
    # nprod - number of products per equation
    # jac_stoi - stoichiometries relevant to Jacobian
    # njac - number of elements of Jacobian affected per equation
    # jac_den_indx - index of denominator components for Jacobian
    # jac_indx - index of Jacobian affected per equation
    # RO2_indx - index of components in peroxy radical list
    # H2Oi - index of water
    # temp - temperature in chamber (K)
    # tempt - times that temperatures reached (s)
    # Pnow - pressure inside chamber (Pa)
    # light_stat - lights status
    # light_time - time light status attained (s)
    # daytime - time of day experiment starts (s)
    # lat - latitude of experiment (degrees)
    # lon - longitude of experiment (degrees)
    # af_path - path to actinic flux values
    # dayOfYear - number of days since 31st December experiment held on
    # photo_path - path to file with absorption cross-sections
    # 		and quantum yields
    # Jlen - number of photochemical reactions
    # con_infl_C - influx of components with constant concentration
    # (molecules/cc/s)
    # nrec_step - number of recording steps
    # dydt_vst - dictionary for holding change tendencies of specified
    #		components
    # siz_str - the size structure
    # num_sb - number of particle size bins
    # num_comp - number of components
    # seedi - index of component(s) comprising seed material
    # seed_name - name(s) of component(s) comprising seed particles
    # seedVr - volume ratio of component(s) comprising seed material
    # core_diss - dissociation constant of seed
    # Psat - pure component saturation vapour pressure
    # 	(molecules/cc (air))
    # mfp - mean free path (m)
    # accom_coeff - accommodation coefficient
    # y_mw - molecular weight (g/mol)
    # surfT - surface tension (g/s2)
    # R_gas - ideal gas constant (kg.m2.s-2.K-1.mol-1)
    # NA - Avogadro's constant (molecules/mol)
    # y_dens - component densities (kg/m3)
    # x - particle radii (um)
    # Varr - particle volume (um3)
    # therm_sp - thermal speed (m/s)
    # act_coeff - activity coefficient
    # Cw - effective absorbing mass of wall (molecules/cc (air))
    # kw - gas-wall mass transfer coefficient (/s)
    # Cfactor - conversion factor for concentrations (ppb/molecules/cc)
    # tf - transmission factor for natural sunlight
    # light_ad - marker for whether to adapt time interval for
    #	changing natural light intensity
    # y_arr - index for arranging concentrations into matrix that
    # 	allows reaction rate coefficient calculation
    # y_rind - index for the concentration array  that
    # 	allows reaction rate coefficient calculation
    # uni_y_rind - unique index of reactants
    # y_pind - index for the concentration array  that
    # 	allows product gains to be indexed
    # uni_y_pind - unique index of products
    # reac_col - column indices for sparse matrix of reaction
    #		losses
    # prod_col - column indices for sparse matrix of production
    #		gains
    # rstoi_flat - 1D array of reactant stoichiometries per
    #	equation
    # pstoi_flat - 1D array of product stoichiometries per
    #	equation
    # rr_arr - index for reaction rates to allow reactant loss
    # 	calculation
    # rr_arr_p - index for reaction rates to allow product gain
    #	calculation
    # rowvals - row indices of Jacobian elements
    # colptrs - indices of  rowvals corresponding to each column of
    # 	the Jacobian
    # wall_on - marker for whether wall partitioning turned on
    # Cw - effective absorbing mass concentration of wall
    #	(molecules/cc (air))
    # kw - mass transfer coefficient of wall partitioning (/s)
    # jac_wall_indx - index of inputs to Jacobian from wall
    # 	partitioning
    # jac_part_indx - index of inputs to Jacobian from particle
    #	partitioning
    # Vbou - volume boundary of size bins (um3)
    # N_perbin - number concentration of particles per size bin
    #	(#/cc (air))
    # Vol0 - initial single particle volumes per size bin (um3)
    # rad0 - initial radius at particle centres (um)
    # np_sum - number concentration of newly nucleated particles
    #		(#/cc (air))
    # new_partr - radius of newly nucleated particles (cm)
    # nucv1, v2, v3 - nucleation parameters
    # nuci - index of nucleating component
    # nuc_comp - the nucleating component
    # nuc_ad - marker for whether to reduce time step to allow
    #	for accurate capture of nucleation
    # RH - relative humidities (fraction 0-1)
    # RHt - times through experiment at which relative humidities reached (s)
    # coag_on - whether coagulation to be modelled
    # inflectDp - particle diameter at which wall loss inflection occurs (m)
    # pwl_xpre - x value preceding inflection point
    # pwl_xpro - x value proceeding inflection point
    # inflectk - deposition rate at inflection (/s)
    # chamR - spherical-equivalent radius of chamber (m2)
    # McMurry_flag - marker for treament of particle deposition to walls
    # p_char - average number of charges per particle (/particle)
    # e_field - average electric field inside chamber (g.m/A.s3)
    # injectt - time of injection of components (s)
    # inj_indx - index of components being instantaneously injected after
    #	experiment start
    # Ct - concentration(s) (ppb) of component(s) injected
    #	instantaneously after experiment start
    # pmode - whether number size distributions expressed as modes or explicitly
    # pconc - concentration of injected particles (#/cc (air))
    # pconct - times of particle injection (s)
    # mean_rad - mean radius for particle number size
    #	distribution (um)
    # lowsize - lower size bin boundary (um)
    # uppsize - upper size bin boundary (um)
    # std - standard deviation for injected particle number size
    #	distributions
    # rbou - size bin radius bounds (um)
    # const_infl_t - times for constant influxes (s)
    # MV - molar volume (cc/mol)
    # rindx_aq - index of reactants for aqueous-phase
    # pindx_aq - index of products for aqueous-phase
    # rstoi_aq - stoichiometry of reactants for aqueous-phase
    # pstoi_aq - stoichiometry of products for aqueous-phase
    # nreac_aq - number of reactants per aqueous-phase reaction
    # nprod_aq - number of products per aqueous-phase reaction
    # jac_stoi_aq - stoichiometry for Jacobian for aqueous-phase
    # njac_aq - number of Jacobian elements per aqueous-phase reaction
    # jac_den_indx_aq - index of Jacobian denominators
    # jac_indx_aq - index of  Jacobian for aqueous-phase
    # y_arr_aq - y indices for aqueous-phase
    # y_rind_aq - reactant indices for aqueous-phase
    # uni_y_rind_aq - y indices for reactants for aqueous-phase
    # y_pind_aq - y indices for products for aqueous-phase
    # uni_y_pind_aq - y indices for products for aqueous-phase
    # reac_col_aq - columns of sparse matrix for aqueous-phase
    # prod_col_aq - columns of sparse matrix for aqueous-phase
    # rstoi_flat_aq - reactant stoichiometries for Jacobian for
    # 	aqueous-phase
    # pstoi_flat_aq - product stoichiometries for Jacobian for
    #	aqueous-phase
    # rr_arr_aq - aqueous-phase reaction rate indices
    # rr_arr_p_aq - aqueous-phase reaction rate indices
    # eqn_num - number of reactions in gas- and aqueous-phase
    # partit_cutoff - the product of saturation vapour pressure
    #	and activity coefficient above which gas-particle
    #	partitioning assumed negligible
    # diff_vol - diffusion volumes of components according to
    #		Fuller et al. (1969)
    # DStar_org - diffusion coefficient of components at initial temperature (cm2/s)
    # corei - index of core component
    # ser_H2O - whether to serialise the gas-particle partitioning of water
    # C_p2w - concentration of components on the wall due to particle
    # deposition to wall (molecules/cc)
    # the following inputs are used only for the saving module:
    # sch_name - path to chemical scheme
    # sav_nam - name of folder to save in
    # comp_namelist - chemical scheme name of components
    # dydt_trak - name of components to track change tendencies
    # space_mode - type of spacing used in particle size distribution
    # rbou00 - original particle size bin bounds
    # ub_rad_amp - amplificatin factor for upper bin size bound
    # indx_plot - indices of components to plot the gas-phase temporal profile of
    # comp0 - names of components to plot the gas-phase temporal profile of
    # inname - path to model variables file
    # rel_SMILES - SMILES strings of components in chemical scheme
    # Psat_Pa_rec - pure component saturation vapour pressures (Pa) at 298.15 K
    # OC - oxygen to carbon ratio of components
    # wat_hist - flag for history of particle-phase with respect to water partitioning,
    # 	where 0 is dry (therefore on the deliquescence curve) and 1 is wet
    #	(therefore on the efflorescence curve)
    # Pybel_objects - the pybel objects for components
    # ------------------------------------------------------------

    # start timer
    st_time = time.time()

    step_no = 0  # track number of time steps
    sumt = 0.0  # track time through simulation (s)
    # counters on updates
    light_time_cnt = 0  # light time status count
    gasinj_cnt = 0  # count on injection times of components
    if (pconct[0, 0] == 0. and len(pconct[0, :]) > 1):
        seedt_cnt = 1  # count on injection times of particles
    else:
        seedt_cnt = 0
    infx_cnt = 0  # count on constant gas-phase influx occurrences
    infx_cnt0 = 0  # remember count at start of integration step
    tempt_cnt = 0  # count on chamber temperatures
    tempt_cnt0 = 0  # remember count at start of integration step
    RHt_cnt = 0  # count on chamber relative humidities
    RHt_cnt0 = 0  # remember count at start of integration step
    save_cnt = 1  # count on recording results

    # count on time since update to integration initial values/constants last called (s)
    update_count = 0.
    y0 = np.zeros(
        (len(y)))  # remember initial concentrations (molecules/cm3 (air))
    N_perbin0 = np.zeros(
        (N_perbin.shape[0], N_perbin.shape[1])
    )  # remember initial particle number concentrations (# particles/cm3)
    x0 = np.zeros((len(x)))  # remember initial particle sizes (um)
    t0 = update_stp  # remember initial integration step (s)
    # flag for changing integration time step due to changing initial values
    ic_red = 0
    tnew = update_stp  # the time to integrate over (s)
    # fraction of newly injected seed particles
    pconcn_frac = 0.

    # prepare recording matrices, including recording of initial
    # conditions, note initial change tendencies not recorded
    # in this call but are below
    [
        trec, yrec, Cfactor_vst, Nres_dry, Nres_wet, x2, seedt_cnt, rbou_rec,
        Cfactor, infx_cnt, yrec_p2w, temp_now, cham_env, Pnow, Psat, RHn
    ] = rec_prep.rec_prep(
        nrec_steps, y, y0, rindx, rstoi, pindx, pstoi, nprod, nreac, num_sb,
        num_comp, N_perbin, core_diss, Psat, mfp, accom_coeff, y_mw, surfT,
        R_gas, temp, tempt, NA, y_dens * 1.e-3, x, therm_sp, H2Oi, act_coeff,
        RO2_indx, sumt, Pnow, light_stat, light_time, light_time_cnt, daytime,
        lat, lon, af_path, dayOfYear, photo_path, Jlen, Cw, kw, Cfactor, tf,
        light_ad, wall_on, Vbou, tnew, nuc_ad, nucv1, nucv2, nucv3, np_sum,
        update_stp, update_count, injectt, gasinj_cnt, inj_indx, Ct, pmode,
        pconc, pconct, seedt_cnt, mean_rad, corei, seed_name, seedVr, lowsize,
        uppsize, rad0, x, std, rbou, const_infl_t, infx_cnt, con_infl_C, MV,
        partit_cutoff, diff_vol, DStar_org, seedi, C_p2w, RH, RHt, tempt_cnt,
        RHt_cnt, Pybel_objects, nuci, nuc_comp, t0)

    importlib.reload(ode_solv)  # import most recent version
    importlib.reload(ode_solv_wat)  # import most recent version
    importlib.reload(dydt_rec)  # import most recent version

    while (tot_time - sumt) > (tot_time / 1.e10):

        # remembering variables at the start of the integration step ------------------------------------------
        y0[:] = y[:]  # remember initial concentrations (molecules/cm3 (air))
        N_perbin0[:] = N_perbin[:]  # remember initial particle number concentration (# particles/cm3)
        x0[:] = x[:]  # remember initial particle sizes (um)
        temp_now0 = temp_now  # remember temperature (K)
        wat_hist0 = wat_hist  # remember water history flag at start of integration step
        RH0 = RHn  # relative humidity at start of integration step
        Pnow0 = Pnow  # pressure (Pa)

        # remember counts at start of integration step
        infx_cnt0 = infx_cnt
        tempt_cnt0 = tempt_cnt
        RHt_cnt0 = RHt_cnt
        seedt_cnt0 = seedt_cnt
        gasinj_cnt0 = gasinj_cnt
        light_time_cnt0 = light_time_cnt

        # --------------------------------------------------------------------------------------------------------------------

        gpp_stab = 0  # flag for stability in gas-particle partitioning
        lin_int = 0  # flag to linearly interpolate changes to chamber
        t00 = tnew  # remember the initial integration step for this integration step (s)

        while (gpp_stab != 1):  # whilst ode solver flagged as unstable

            # if integration interval decreased, reset concentrations to those at start of interval
            if (gpp_stab == -1):
                y[:] = y0[:]  # (molecules/cm3)

            # update chamber variables
            [
                temp_now, Pnow, lightm, light_time_cnt, tnew, ic_red,
                update_stp, update_count, Cinfl_now, seedt_cnt, Cfactor,
                infx_cnt, gasinj_cnt, DStar_org, y, tempt_cnt, RHt_cnt, Psat,
                N_perbin, x, pconcn_frac
            ] = cham_up.cham_up(
                sumt, temp, tempt, Pnow0, light_stat, light_time,
                light_time_cnt0, light_ad, tnew, nuc_ad, nucv1, nucv2, nucv3,
                np_sum, update_stp, update_count, lat, lon, dayOfYear,
                photo_path, af_path, injectt, gasinj_cnt0, inj_indx, Ct, pmode,
                pconc, pconct, seedt_cnt0, num_comp, y0, y, N_perbin0,
                mean_rad, corei, seedVr, seed_name, lowsize, uppsize, num_sb,
                MV, rad0, x0, std, y_dens, H2Oi, rbou, const_infl_t, infx_cnt0,
                con_infl_C, wall_on, Cfactor, seedi, diff_vol, DStar_org, RH,
                RHt, tempt_cnt0, RHt_cnt0, Pybel_objects, nuci, nuc_comp, y_mw,
                temp_now0, Psat, gpp_stab, t00, x0)

            # ensure end of time interval does not surpass recording time
            if ((sumt + tnew) > save_stp * save_cnt):
                tnew = (save_stp * save_cnt) - sumt
                ic_red = 1

            # ensure update to operator-split processes interval not surpassed
            if (update_count + tnew > update_stp):
                tnew = (update_stp - update_count)
                ic_red = 1

            # ensure simulation end time not surpassed
            if (sumt + tnew > tot_time):
                tnew = (tot_time - sumt)
                ic_red = 1

            if ((num_sb - wall_on) > 0
                    and (sum(N_perbin) > 0)):  # if particles present

                # update partitioning variables
                [kimt, kelv_fac] = partit_var.kimt_calc(
                    y, mfp, num_sb, num_comp, accom_coeff, y_mw, surfT, R_gas,
                    temp_now, NA, y_dens, N_perbin,
                    x.reshape(1, -1) * 1.e-6, Psat, therm_sp, H2Oi, act_coeff,
                    wall_on, 1, partit_cutoff, Pnow, DStar_org)

                # update particle-phase activity coefficients, note the output,
                # note that if ODE solver unstable, then y resets to y0 via
                # the cham_up module prior to this call
                [act_coeff, wat_hist, RHn, y, dydt_erh_flag
                 ] = act_coeff_update.ac_up(y, H2Oi, RH0, temp_now, wat_hist0,
                                            act_coeff, num_comp,
                                            (num_sb - wall_on))

            else:  # fillers
                kimt = np.zeros((num_sb - wall_on, num_comp))
                kelv_fac = np.zeros((num_sb - wall_on, 1))
                dydt_erh_flag = 0

            # reaction rate coefficient
            rrc = rrc_calc.rrc_calc(RO2_indx, y[H2Oi], temp_now, lightm, y,
                                    daytime + sumt, lat, lon, af_path,
                                    dayOfYear, Pnow, photo_path, Jlen, tf)

            # update Jacobian inputs based on particle-phase fractions of components
            [
                rowvalsn, colptrsn, jac_part_indxn, jac_mod_len,
                jac_part_hmf_indx, rw_indx, jac_wall_indxn, jac_part_H2O_indx
            ] = jac_up.jac_up(y[num_comp:num_comp * ((num_sb - wall_on + 1))],
                              rowvals, colptrs, (num_sb - wall_on), num_comp,
                              jac_part_indx, H2Oi, y[H2Oi], jac_wall_indx,
                              ser_H2O)

            # before solving ODEs for chemistry, gas-particle partitioning and gas-wall partitioning,
            # estimate and record any change tendencies (molecules/cm3/s) resulting from these processes
            if (len(dydt_vst) > 0):

                # record any change tendencies of specified components
                dydt_vst = dydt_rec.dydt_rec(y, rindx, rstoi, rrc, pindx,
                                             pstoi, nprod, save_cnt - 1,
                                             dydt_vst, nreac, num_sb, num_comp,
                                             pconc, core_diss, Psat, kelv_fac,
                                             kimt, kw, Cw, act_coeff, seedi,
                                             dydt_erh_flag, H2Oi, wat_hist)

            if (ser_H2O == 1 and (num_sb - wall_on) > 0
                    and (sum(N_perbin) >
                         0)):  # if water gas-particle partitioning serialised

                # if on the deliquescence curve rather than the efflorescence curve in terms of water gas-particle partitioning
                if (wat_hist == 1):

                    # call on ode solver for water
                    [y, res_t] = ode_solv_wat.ode_solv(
                        y, tnew, rindx, pindx, rstoi, pstoi, nreac, nprod, rrc,
                        jac_stoi, njac, jac_den_indx, jac_indx, Cinfl_now,
                        y_arr, y_rind, uni_y_rind, y_pind, uni_y_pind,
                        reac_col, prod_col, rstoi_flat, pstoi_flat, rr_arr,
                        rr_arr_p, rowvalsn, colptrsn, num_comp, num_sb,
                        wall_on, Psat, Cw, act_coeff, kw, jac_wall_indxn,
                        seedi, core_diss, kelv_fac, kimt, (num_sb - wall_on),
                        jac_part_indxn, rindx_aq, pindx_aq, rstoi_aq, pstoi_aq,
                        nreac_aq, nprod_aq, jac_stoi_aq, njac_aq,
                        jac_den_indx_aq, jac_indx_aq, y_arr_aq, y_rind_aq,
                        uni_y_rind_aq, y_pind_aq, uni_y_pind_aq, reac_col_aq,
                        prod_col_aq, rstoi_flat_aq, pstoi_flat_aq, rr_arr_aq,
                        rr_arr_p_aq, eqn_num, jac_mod_len, jac_part_hmf_indx,
                        rw_indx, N_perbin, jac_part_H2O_indx, H2Oi)

                    if (any(y[H2Oi::num_comp] < 0.)
                        ):  # check on stability of water partitioning

                        y_H2O = y[
                            H2Oi::
                            num_comp]  # isolate just water concentrations (molecules/cm3)
                        # sum the negative concentrations and convert to absolute value (molecules/cm3)
                        neg_H2O = np.abs(sum(y_H2O[y_H2O < 0.]))

                        # allow a given fraction of water concentrations to be negative
                        if (neg_H2O / sum(np.abs(y[H2Oi::num_comp])) > 0.):

                            gpp_stab = -1  # maintain unstable flag
                            # tell user what's happening
                            yield (str(
                                'Note: negative water concentration generated following call to ode_solv_wat module, the programme assumes this is because of a change in relative humidity in chamber air, and will automatically half the integration time interval and linearly interpolate any change to chamber conditions supplied by the user.  To stop this the simulation must be cancelled using the Quit button in the PyCHAM graphical user interface.  Current update time interval is '
                                + str(tnew) + ' seconds'))

                            if (
                                    tnew < 1.e-20
                            ):  # if time step has decreased to unreasonably low and solver still unstable then break
                                yield (str(
                                    'Error: negative concentrations generated following call to ode_solv_wat module, the programme has assumed this is because of a change in chamber condition (e.g. injection of components), and has automatically halved the integration time interval and linearly interpolated any change to chamber conditions supplied by the user.  However, the integration time interval has now decreased to '
                                    + str(tnew) +
                                    ' seconds, which is assumed too small to be useful, so the programme has been stopped.'
                                ))

                        else:  # if less than 0.1 % negative
                            gpp_stab = 1  # change to stable flag

                    else:  # if solution stable, change stability flag to represent this
                        gpp_stab = 1  # change to stable flag

                # zero partitioning of water to particles for integration without water gas-particle partitioning
                kimt[:, H2Oi] = 0.

            # model component concentration changes to get new concentrations
            # (molecules/cc (air))
            [y, res_t] = ode_solv.ode_solv(
                y, tnew, rindx, pindx, rstoi, pstoi, nreac, nprod, rrc,
                jac_stoi, njac, jac_den_indx, jac_indx, Cinfl_now, y_arr,
                y_rind, uni_y_rind, y_pind, uni_y_pind, reac_col, prod_col,
                rstoi_flat, pstoi_flat, rr_arr, rr_arr_p, rowvalsn, colptrsn,
                num_comp, num_sb, wall_on, Psat, Cw, act_coeff, kw,
                jac_wall_indxn, seedi, core_diss, kelv_fac, kimt,
                (num_sb - wall_on), jac_part_indxn, rindx_aq, pindx_aq,
                rstoi_aq, pstoi_aq, nreac_aq, nprod_aq, jac_stoi_aq, njac_aq,
                jac_den_indx_aq, jac_indx_aq, y_arr_aq, y_rind_aq,
                uni_y_rind_aq, y_pind_aq, uni_y_pind_aq, reac_col_aq,
                prod_col_aq, rstoi_flat_aq, pstoi_flat_aq, rr_arr_aq,
                rr_arr_p_aq, eqn_num, jac_mod_len, jac_part_hmf_indx, rw_indx,
                N_perbin, jac_part_H2O_indx, H2Oi)

            if (any(y < 0.)):  # check on stability of integration of processes

                # identify components with negative concentrations
                neg_comp_indx = y < 0.
                # transform into components in columns, locations in rows
                neg_comp_indx = neg_comp_indx.reshape(num_sb + 1, num_comp)
                # get component indices with negative concentration
                neg_comp_indx = (np.where(neg_comp_indx == 1))[1]

                # loop through components with negative concentrations
                for ci in neg_comp_indx:
                    all_c = y[ci::num_comp]
                    # sum of negative concentrations
                    neg_c = np.abs(sum(all_c[all_c < 0.]))
                    # sum of absolute of all concentrations
                    sum_c = sum(np.abs(all_c))

                    # allow a given fraction to be negative, but any more suggests ODE solver instability
                    if (neg_c / sum_c > 0.):

                        gpp_stab = -1  # maintain unstable flag
                        # tell user what's happening
                        yield (str(
                            'Note: negative concentrations generated following call to ode_solv module, the programme assumes this is because of a change in chamber condition (e.g. injection of components), and will automatically half the integration time interval and linearly interpolate any change to chamber conditions supplied by the user.  To stop this the simulation must be cancelled using the Quit button in the PyCHAM graphical user interface.  Current integration time interval is '
                            + str(tnew) + ' seconds'))

                        if (
                                tnew < 1.e-20
                        ):  # if time step has decreased to unreasonably low and solver still unstable then break
                            yield (str(
                                'Error: negative concentrations generated following call to ode_solv module, the programme has assumed this is because of a change in chamber condition (e.g. injection of components), and has automatically halved the integration time interval and linearly interpolated any change to chamber conditions supplied by the user.  However, the integration time interval has now decreased to '
                                + str(tnew) +
                                ' seconds, which is assumed too small to be useful, so the programme has been stopped.'
                            ))

                        # if negative concentration too great a proportion of total
                        # concentration then stop loop through components with negative concentrations
                        continue

                    else:  # if less than 0.1 % negative
                        gpp_stab = 1  # change to stable flag

            else:  # if solution stable, change stability flag to represent this

                # account for any partial addition of newly injected seed particles
                pconc[:, seedt_cnt] -= pconc[:, seedt_cnt] * pconcn_frac
                # reset fraction of newly injected seed particles
                pconcn_frac = 0.
                gpp_stab = 1  # change to stable flag

            # half the update time step (s) if necessary
            if (gpp_stab == -1):
                tnew = tnew / 2.

        # end of integration stability condition section ----------------------------
        step_no += 1  # track number of steps
        sumt += tnew  # total time through simulation (s)

        if ((num_sb - wall_on) > 0):  # if particle size bins present
            # update particle sizes
            if ((num_sb - wall_on) > 1) and (any(
                    N_perbin > 1.e-10)):  # if particles present

                if (siz_str == 0):  # moving centre
                    (N_perbin, Varr, y, x, redt, t,
                     bc_red) = mov_cen.mov_cen_main(N_perbin, Vbou, num_sb,
                                                    num_comp, y_mw, x, Vol0,
                                                    tnew, update_stp, y0, MV,
                                                    Psat[0, :], ic_red, y,
                                                    res_t, wall_on)

                if redt == 1:
                    import ipdb
                    ipdb.set_trace()

                if (siz_str == 1):  # full-moving
                    (Varr, x, y[num_comp:(num_comp * (num_sb - wall_on + 1))],
                     N_perbin, Vbou, rbou) = fullmov.fullmov(
                         (num_sb - wall_on), N_perbin, num_comp,
                         y[num_comp:(num_comp) * (num_sb - wall_on + 1)],
                         MV * 1.e12, Vol0, Vbou, rbou)

            update_count += tnew  # time since operator-split processes last called (s)

            # if time met to implement operator-split processes
            if (update_count >= (update_stp * 9.999999e-1)):
                if (any(N_perbin > 1.e-10)):

                    # particle-phase concentration(s) (molecules/cc (air))
                    Cp = np.transpose(y[num_comp:(num_comp) *
                                        (num_sb - wall_on + 1)].reshape(
                                            num_sb - wall_on, num_comp))

                    # coagulation
                    [
                        N_perbin,
                        y[num_comp:(num_comp) * (num_sb - wall_on + 1)], x, Gi,
                        eta_ai, Varr, Vbou, rbou
                    ] = coag.coag(RH[RHt_cnt], temp_now, x * 1.e-6,
                                  (Varr * 1.0e-18).reshape(1, -1),
                                  y_mw.reshape(-1, 1), x * 1.e-6, Cp,
                                  (N_perbin).reshape(1, -1), update_count,
                                  (Vbou * 1.0e-18).reshape(1,
                                                           -1), rbou, num_comp,
                                  0, (np.squeeze(y_dens * 1.e-3)), Vol0, rad0,
                                  Pnow, 0, Cp, (N_perbin).reshape(1, -1),
                                  (Varr * 1.e-18).reshape(1, -1), coag_on,
                                  siz_str, wall_on)

                    if ((McMurry_flag > -1) and
                        (wall_on == 1)):  #if particle loss to walls turned on
                        # particle loss to walls
                        [
                            N_perbin,
                            y[num_comp:(num_comp) * (num_sb - wall_on + 1)]
                        ] = wallloss.wallloss(
                            N_perbin.reshape(-1, 1),
                            y[num_comp:(num_comp) * (num_sb - wall_on + 1)],
                            Gi, eta_ai, x * 2.0e-6, y_mw, Varr * 1.0e-18,
                            (num_sb - wall_on), num_comp, temp_now,
                            update_count, inflectDp, pwl_xpre, pwl_xpro,
                            inflectk, chamR, McMurry_flag, 0, p_char, e_field,
                            (num_sb - wall_on), C_p2w)

                if (nucv1 > 0.):  # nucleation

                    [N_perbin, y, x, Varr, np_sum, rbou,
                     Vbou] = nuc.nuc(sumt, np_sum, N_perbin, y,
                                     y_mw.reshape(-1, 1),
                                     np.squeeze(y_dens * 1.0e-3), num_comp,
                                     Varr, x, new_partr, MV, nucv1, nucv2,
                                     nucv3, nuc_comp[0], siz_str, rbou, Vbou,
                                     (num_sb - wall_on))

                # reset count to that since original operator-split processes interval met (s)
                update_count = sumt % t0

        # update the percentage time in the GUI progress bar
        yield (sumt / tot_time * 100.)

        # record output
        if ((sumt - (save_stp * save_cnt) > -1.e-10)
                or (sumt >= (tot_time - tot_time / 1.e10))):

            [
                trec, yrec, Cfactor_vst, save_cnt, Nres_dry, Nres_wet, x2,
                rbou_rec, yrec_p2w, cham_env
            ] = rec.rec(save_cnt, trec, yrec, Cfactor_vst, y, sumt, rindx,
                        rstoi, rrc, pindx, pstoi, nprod, nreac, num_sb,
                        num_comp, N_perbin, core_diss, Psat, kelv_fac, kimt,
                        kw, Cw, act_coeff, Cfactor, Nres_dry, Nres_wet, x2, x,
                        MV, H2Oi, Vbou, rbou, wall_on, rbou_rec, seedi,
                        yrec_p2w, C_p2w, cham_env, temp_now, Pnow)

        # if time step was temporarily reduced, then return
        if (ic_red == 1):
            update_stp = t0
            tnew = update_stp
            ic_red = 0

        # remember the gas-phase water concentration from previous
        # integration step (molecules/cm3)
        y_H2O0 = y[H2Oi]

    time_taken = time.time() - st_time

    # save results
    save.saving(sch_name, yrec, Nres_dry, Nres_wet, trec, sav_nam, dydt_vst,
                num_comp, Cfactor_vst, 0, num_sb, comp_namelist, dydt_trak,
                y_mw, MV, time_taken, seed_name, x2, rbou_rec, wall_on,
                space_mode, rbou00, ub_rad_amp, indx_plot, comp0, yrec_p2w,
                sch_name, inname, rel_SMILES, Psat_Pa_rec, OC, H2Oi, seedi,
                siz_str, cham_env)
    return ()
예제 #9
0
import rec
import baidu_voice

TEXT = rec.rec()

TEXT = baidu_voice.get_asr('rec_temp.wav')

print('识别的结果是: ' + TEXT)
예제 #10
0
# -*- coding: utf-8 -*-
#!usr/bin/env python3
import receive
import send
import rec
import speak

while (True):
    print('start!')
    listen = rec.rec(7)
    if listen == '我要发邮件':
        send.main()
    elif listen == '最近一封邮件':
        receive.main()
    elif listen == '结束':
        speak.say('end.wav')
        break
    else:
        speak.say('respeak.wav')
예제 #11
0
import subprocess as sub
from rec import rec
import processSTT	
from command import Command

if __name__ == "__main__":
	sub.call("tts 'initiating room automation system'",shell=True)
	Command.initCommands()
	while True:
		empty=rec(6)
		if not empty:
			processSTT.process(open("stt.txt",'r'))
예제 #12
0
def ode_updater(update_stp, 
	tot_time, save_stp, y, rindx, 
	pindx, rstoi, pstoi, nreac, nprod, jac_stoi, njac, 
	jac_den_indx, jac_indx, RO2_indx, H2Oi,	temp, tempt, 
	Pnow, light_stat, light_time, daytime, lat, lon, af_path, 
	dayOfYear, photo_path, Jlen, con_infl_C, nrec_steps, 
	dydt_vst, siz_str, num_sb, num_comp, seedi, seed_name, seedVr, 
	core_diss, Psat, mfp, therm_sp,
	accom_coeff, y_mw, surfT, R_gas, NA, y_dens, 
	x, Varr, act_coeff, Cw, kw, Cfactor, tf, light_ad, y_arr, 
	y_rind, 
	uni_y_rind, y_pind, uni_y_pind, reac_col, prod_col, 
	rstoi_flat, pstoi_flat, rr_arr, rr_arr_p, rowvals, 
	colptrs, wall_on, jac_wall_indx, jac_part_indx, Vbou,
	N_perbin, Vol0, rad0, np_sum, new_partr, nucv1, nucv2, 
	nucv3, nuc_comp, nuc_ad, RH, coag_on, inflectDp, pwl_xpre, 
	pwl_xpro, inflectk, chamR, Rader, p_char, e_field, 
	injectt, inj_indx, Ct, pmode, pconc, pconct, mean_rad, lowsize, 
	uppsize, std, rbou, const_infl_t, MV,
	rindx_aq, 
	pindx_aq, rstoi_aq, pstoi_aq, nreac_aq, nprod_aq, jac_stoi_aq, njac_aq, 
	jac_den_indx_aq, jac_indx_aq, y_arr_aq,
	y_rind_aq, 
	uni_y_rind_aq, y_pind_aq, uni_y_pind_aq, reac_col_aq, prod_col_aq, 
	rstoi_flat_aq, pstoi_flat_aq, rr_arr_aq, rr_arr_p_aq, eqn_num, 
	partit_cutoff, coll_dia, corei):

	import ode_solv # import most updated version
	# inputs: ----------------------------------------------------
	# update_stp - interval at which to update integration 
	#		constants (s)
	# tot_time - total time to simulate (s)
	# save_stp - frequency to save results (s)
	# y - initial component concentrations (molecules/cc/s)
	# rindx - index of reactants per equation
	# pindx - index of products per equation
	# nreac - number of reactants per equation
	# nprod - number of products per equation
	# jac_stoi - stoichiometries relevant to Jacobian
	# njac - number of elements of Jacobian affected per equation
	# jac_den_indx - index of denominator components for Jacobian
	# jac_indx - index of Jacobian affected per equation
	# RO2_indx - index of components in peroxy radical list
	# H2Oi - index of water
	# temp - temperature in chamber (K)
	# tempt - times that temperatures reached (s)
	# Pnow - pressure inside chamber (Pa)
	# light_stat - lights status
	# light_time - time light status attained (s)
	# daytime - time of day experiment starts (s)
	# lat - latitude of experiment (degrees)
	# lon - longitude of experiment (degrees)
	# af_path - path to actinic flux values
	# dayOfYear - number of days since 31st December experiment held on
	# photo_path - path to file with absorption cross-sections
	# 		and quantum yields
	# Jlen - number of photochemical reactions
	# con_infl_C - influx of components with constant concentration
	# (molecules/cc/s)
	# nrec_step - number of recording steps
	# dydt_vst - dictionary for holding change tendencies of specified
	#		components
	# siz_str - the size structure
	# num_sb - number of particle size bins
	# num_comp - number of components
	# seedi - index of component(s) comprising seed material
	# seed_name - name(s) of component(s) comprising seed particles
	# seedVr - volume ratio of component(s) comprising seed material
	# core_diss - dissociation constant of seed
	# Psat - pure component saturation vapour pressure 
	# 	(molecules/cc (air))
	# mfp - mean free path (m)
	# accom_coeff - accommodation coefficient
	# y_mw - molecular weight (g/mol)
	# surfT - surface tension (g/s2)
	# R_gas - ideal gas constant (kg.m2.s-2.K-1.mol-1)
	# NA - Avogadro's constant (molecules/mol)
	# y_dens - component densities (kg/m3)
	# x - particle radii (um)
	# Varr - particle volume (um3)
	# therm_sp - thermal speed (m/s)
	# act_coeff - activity coefficient
	# Cw - effective absorbing mass of wall (molecules/cc (air))
	# kw - gas-wall mass transfer coefficient (/s)
	# Cfactor - conversion factor for concentrations (ppb/molecules/cc)
	# tf - transmission factor for natural sunlight
	# light_ad - marker for whether to adapt time interval for 
	#	changing natural light intensity
	# y_arr - index for arranging concentrations into matrix that 
	# 	allows reaction rate coefficient calculation
	# y_rind - index for the concentration array  that 
	# 	allows reaction rate coefficient calculation
	# uni_y_rind - unique index of reactants
	# y_pind - index for the concentration array  that 
	# 	allows product gains to be indexed
	# uni_y_pind - unique index of products
	# reac_col - column indices for sparse matrix of reaction 
	#		losses
	# prod_col - column indices for sparse matrix of production
	#		gains
	# rstoi_flat - 1D array of reactant stoichiometries per 
	#	equation
	# pstoi_flat - 1D array of product stoichiometries per
	#	equation
	# rr_arr - index for reaction rates to allow reactant loss
	# 	calculation
	# rr_arr_p - index for reaction rates to allow product gain
	#	calculation
	# rowvals - row indices of Jacobian elements
	# colptrs - indices of  rowvals corresponding to each column of
	# 	the Jacobian
	# wall_on - marker for whether wall partitioning turned on
	# Cw - effective absorbing mass concentration of wall 
	#	(molecules/cc (air))
	# kw - mass transfer coefficient of wall partitioning (/s)
	# jac_wall_indx - index of inputs to Jacobian from wall 
	# 	partitioning
	# jac_part_indx - index of inputs to Jacobian from particle
	#	partitioning
	# Vbou - volume boundary of size bins (um3)
	# N_perbin - number concentration of particles per size bin 
	#	(#/cc (air))
	# Vol0 - initial single particle volumes per size bin (um3)
	# rad0 - initial radius at particle centres (um)
	# np_sum - number concentration of newly nucleated particles 
	#		(#/cc (air))
	# new_partr - radius of newly nucleated particles (cm)
	# nucv1, v2, v3 - nucleation parameters
	# nuc_comp - the nucleating component
	# nuc_ad - marker for whether to reduce time step to allow 
	#	for accurate capture of nucleation
	# RH - relative humidity
	# coag_on - whether coagulation to be modelled
	# inflectDp - particle diameter at which wall loss inflection occurs (m)
	# pwl_xpre - x value preceding inflection point
	# pwl_xpro - x value proceeding inflection point
	# inflectk - deposition rate at inflection (/s)
	# chamR - spherical-equivalent radius of chamber (m2)
	# Rader - marker for treamnt of particle deposition to walls
	# p_char - average number of charges per particle (/particle)
	# e_field - average electric field inside chamber (g.m/A.s3)
	# injectt - time of injection of components (s)
	# inj_indx - index of component(s) being injected after 
	#	experiment start
	# Ct - concentration(s) (ppb) of component(s) injected 
	#	instantaneously after experiment start
	# pmode - whether number size distributions expressed as modes or explicitly
	# pconc - concentration of injected particles (#/cc (air))
	# pconct - times of particle injection (s)
	# mean_rad - mean radius for particle number size 
	#	distribution (um)
	# lowsize - lower size bin boundary (um)
	# uppsize - upper size bin boundary (um)
	# std - standard deviation for injected particle number size 
	#	distributions
	# rbou - size bin radius bounds (um)
	# const_infl_t - times for constant influxes (s)
	# MV - molar volume (cc/mol)
	# rindx_aq - index of reactants for aqueous-phase 
	# pindx_aq - index of products for aqueous-phase
	# rstoi_aq - stoichiometry of reactants for aqueous-phase
	# pstoi_aq - stoichiometry of products for aqueous-phase
	# nreac_aq - number of reactants per aqueous-phase reaction
	# nprod_aq - number of products per aqueous-phase reaction
	# jac_stoi_aq - stoichiometry for Jacobian for aqueous-phase
	# njac_aq - number of Jacobian elements per aqueous-phase reaction 
	# jac_den_indx_aq - index of Jacobian denominators 
	# jac_indx_aq - index of  Jacobian for aqueous-phase
	# y_arr_aq - y indices for aqueous-phase
	# y_rind_aq - reactant indices for aqueous-phase 
	# uni_y_rind_aq - y indices for reactants for aqueous-phase
	# y_pind_aq - y indices for products for aqueous-phase
	# uni_y_pind_aq - y indices for products for aqueous-phase
	# reac_col_aq - columns of sparse matrix for aqueous-phase
	# prod_col_aq - columns of sparse matrix for aqueous-phase
	# rstoi_flat_aq - reactant stoichiometries for Jacobian for 
	# 	aqueous-phase
	# pstoi_flat_aq - product stoichiometries for Jacobian for
	#	aqueous-phase
	# rr_arr_aq - aqueous-phase reaction rate indices
	# rr_arr_p_aq - aqueous-phase reaction rate indices
	# eqn_num - number of reactions in gas- and aqueous-phase
	# partit_cutoff - the product of saturation vapour pressure
	#	and activity coefficient above which gas-particle
	#	partitioning assumed negligible
	# coll_dia - collision diameter of components (cm)
	# corei - index of core component
	# ------------------------------------------------------------
	
	step_no = 0 # track number of time steps
	sumt = 0.0 # track time through simulation (s)
	# counters on updates
	light_time_cnt = 0 # light time status count
	gasinj_cnt = 0 # count on injection times of components
	if pconct[0, 0] == 0.: 
		seedt_cnt = 1 # count on injection times of particles
	else:
		seedt_cnt = 0
	infx_cnt = 0 # count on constant gas-phase influx occurrences
	save_cnt = 1 # count on recording results
	# count on time since update to integration initial values/constants last called (s)
	update_count = 0.
	y0 = np.zeros((len(y))) # remember initial concentrations (molecules/cc (air))
	t0 = update_stp # remember initial integration step (s)
	# flag for changing integration time step due to changing initial values	
	ic_red = 0
	tnew = update_stp # the time to integrate over (s)
	
	# prepare recording matrices, including recording of initial
	# conditions
	[trec, yrec, dydt_vst, Cfactor_vst, Nres_dry, Nres_wet, x2, 
	seedt_cnt, rbou_rec, Cfactor, infx_cnt, coll_dia] = rec_prep.rec_prep(nrec_steps, 
	y, rindx, 
	rstoi, pindx, pstoi, nprod, dydt_vst, nreac, 
	num_sb, num_comp, N_perbin, core_diss, Psat, mfp,
	accom_coeff, y_mw, surfT, R_gas, temp, tempt, NA,
	y_dens*1.e-3, x, therm_sp, H2Oi, act_coeff,
	RO2_indx, sumt, Pnow, light_stat, light_time, 
	light_time_cnt, daytime, lat, lon, af_path, 
	dayOfYear, photo_path, Jlen, Cw, kw, Cfactor, tf, 
	light_ad, wall_on, Vbou, tnew, nuc_ad, nucv1, nucv2, nucv3, 
	np_sum, update_stp, update_count, injectt, gasinj_cnt, 
	inj_indx, Ct, pmode, pconc, pconct, seedt_cnt, mean_rad, corei, 
	seed_name, seedVr, lowsize, uppsize, rad0, x, std, rbou, const_infl_t, 
	infx_cnt, con_infl_C, MV, partit_cutoff, coll_dia, seedi)

	print('Starting loop through update steps')	
	while (tot_time-sumt)>(tot_time/1.e10):
		
		y0[:] = y[:] # remember initial concentrations (molecules/cc (air))
				
		# update chamber variables
		[temp_now, Pnow, lightm, light_time_cnt, tnew, ic_red, update_stp, 
			update_count, Cinfl_now, seedt_cnt, Cfactor, infx_cnt, 
			gasinj_cnt, coll_dia] = cham_up.cham_up(sumt, temp, tempt, 
			Pnow, light_stat, light_time, light_time_cnt, light_ad, 
			tnew, nuc_ad, nucv1, nucv2, nucv3, np_sum, 
			update_stp, update_count, lat, lon, dayOfYear, photo_path, 
			af_path, injectt, gasinj_cnt, inj_indx, Ct, pmode, pconc, pconct, 
			seedt_cnt, num_comp, y, N_perbin, mean_rad, corei, seedVr, seed_name, 
			lowsize, uppsize, num_sb, MV, rad0, x, std, y_dens, H2Oi, rbou, 
			const_infl_t, infx_cnt, con_infl_C, wall_on, Cfactor, seedi, coll_dia)
		
		# ensure end of time interval does not surpass recording time
		if ((sumt+tnew) > save_stp*save_cnt):
			tnew = (save_stp*save_cnt)-sumt
			ic_red = 1

		# ensure update step interval not surpassed
		if (update_count+tnew > update_stp):
			tnew = (update_stp-update_count)
			ic_red = 1
		
		if ((num_sb-wall_on) > 0): # if particles present

			# update partitioning variables
			[kimt, kelv_fac] = partit_var.kimt_calc(y, mfp, num_sb, num_comp, accom_coeff, y_mw,   
			surfT, R_gas, temp_now, NA, y_dens, N_perbin, 
			x.reshape(1, -1)*1.0e-6, Psat, therm_sp, H2Oi, act_coeff, wall_on, 1, partit_cutoff, 
			Pnow, coll_dia)
						
		else: # fillers
			kimt = kelv_fac = 0.
		
		# reaction rate coefficient
		rrc = rrc_calc.rrc_calc(RO2_indx, 
			y[H2Oi], temp_now, lightm, y, daytime+sumt, 
			lat, lon, af_path, dayOfYear, Pnow, 
			photo_path, Jlen, tf)
		
		# model component concentration changes to get new concentrations
		# (molecules/cc)
		[res, res_t] = ode_solv.ode_solv(y, tnew, rindx, pindx, rstoi, pstoi,
			nreac, nprod, rrc, jac_stoi, njac, jac_den_indx, jac_indx,
			Cinfl_now, y_arr, y_rind, uni_y_rind, y_pind, uni_y_pind, 
			reac_col, prod_col, rstoi_flat, 
			pstoi_flat, rr_arr, rr_arr_p, rowvals, colptrs, num_comp, 
			num_sb, wall_on, Psat, Cw, act_coeff, kw, jac_wall_indx,
			seedi, core_diss, kelv_fac, kimt, (num_sb-wall_on), 
			jac_part_indx,
			rindx_aq, pindx_aq, rstoi_aq, pstoi_aq,
			nreac_aq, nprod_aq, jac_stoi_aq, njac_aq, jac_den_indx_aq, jac_indx_aq, 
			y_arr_aq, y_rind_aq, uni_y_rind_aq, y_pind_aq, uni_y_pind_aq, 
			reac_col_aq, prod_col_aq, rstoi_flat_aq, 
			pstoi_flat_aq, rr_arr_aq, rr_arr_p_aq, eqn_num)
		
		# take last installment from res
		y = res[-1, :]
		
		step_no += 1 # track number of steps
		sumt += tnew # total time through simulation (s)
		
		if (num_sb-wall_on > 0): # if particle size bins present
			# update particle sizes
			if ((num_sb-wall_on) > 1) and ((N_perbin > 1.0e-10).sum()>0): # if particles present
				
				if (siz_str == 0): # moving centre
					(N_perbin, Varr, y, x, redt, t, bc_red) = mov_cen.mov_cen_main(N_perbin, 
					Vbou, num_sb, num_comp, y_mw, x, Vol0, tnew, 
					update_stp, y0, MV, Psat[0, :], ic_red, res, res_t)
				if (siz_str == 1): # full-moving
					(Varr, x, y[num_comp:(num_comp*(num_sb-wall_on+1))], 
					N_perbin, Vbou, rbou) = fullmov.fullmov((num_sb-wall_on), N_perbin,
 					num_comp, y[num_comp:(num_comp)*(num_sb-wall_on+1)], MV*1.e12, 
					Vol0, Vbou, rbou)
			
			update_count += tnew # time since operator-split processes last called (s)

			# if time met to implement operator-split processes
			if (update_count>=update_stp*9.999999e-1):
				if ((N_perbin>1.e-10).sum()>0):
					# particle-phase concentrations (molecules/cc (air))
					Cp = np.transpose(y[num_comp:(num_comp)*(num_sb-wall_on+1)].reshape(num_sb-wall_on, num_comp))
					# coagulation
					[N_perbin, y[num_comp:(num_comp)*(num_sb-wall_on+1)], x, Gi, eta_ai, 
						Varr, Vbou, rbou] = coag.coag(RH, temp_now, x*1.0e-6, 
						(Varr*1.0e-18).reshape(1, -1), 
						y_mw.reshape(-1, 1), x*1.0e-6, 
						Cp, (N_perbin).reshape(1, -1), update_count, 
						(Vbou*1.0e-18).reshape(1, -1), rbou,
						num_comp, 0, (np.squeeze(y_dens*1.0e-3)), Vol0, rad0, Pnow, 0,
						Cp, (N_perbin).reshape(1, -1), (Varr*1.0e-18).reshape(1, -1),
						coag_on, siz_str, wall_on)
				
					if ((Rader>-1) and (wall_on == 1)): #if particle loss to walls turned on
						# particle loss to walls
						[N_perbin, 
						y[num_comp:(num_comp)*(num_sb-wall_on+1)]] = wallloss.wallloss(
							N_perbin.reshape(-1, 1), 
							y[num_comp:(num_comp)*(num_sb-wall_on+1)], Gi, eta_ai,
 							x*2.0e-6, y_mw, 
							Varr*1.0e-18, num_sb, num_comp, temp_now, update_count, 
							inflectDp, pwl_xpre, pwl_xpro, inflectk, chamR, Rader, 
							0, p_char, e_field, (num_sb-wall_on))
			
				if (nucv1 > 0.): # nucleation
					[N_perbin, y, x, Varr, np_sum, rbou, Vbou] = nuc.nuc(sumt, np_sum, 
						N_perbin, y, y_mw.reshape(-1, 1), 
						np.squeeze(y_dens*1.0e-3),  
						num_comp, Varr, x, new_partr, MV, nucv1, nucv2, 
						nucv3, nuc_comp[0], siz_str, rbou, Vbou, (num_sb-wall_on))
					
				# reset count to that since original operator-split processes interval met (s)
				update_count = sumt%t0

		
		print('time through simulation (s): ', sumt)
		
		# record output
		if sumt-(save_stp*save_cnt)>-1.e-10:
			
			[trec, yrec, dydt_vst, Cfactor_vst, save_cnt, 
				Nres_dry, Nres_wet, x2, rbou_rec] = rec.rec(save_cnt, trec, yrec, 
				dydt_vst, Cfactor_vst, y, sumt, rindx, rstoi, rrc, pindx, pstoi, 
				nprod, nreac, num_sb, num_comp, N_perbin, core_diss, 
				Psat, kelv_fac, kimt, kw, Cw, act_coeff, Cfactor, Nres_dry, 
				Nres_wet, x2, x, MV, H2Oi, Vbou, rbou, wall_on, rbou_rec, seedi)		
		
		# if time step was temporarily reduced, then return
		if ic_red == 1:
			update_stp = t0
			tnew = update_stp
			ic_red = 0
	
	return(trec, yrec, dydt_vst, Cfactor_vst, Nres_dry, Nres_wet, x2, rbou_rec)
예제 #13
0
파일: robot.py 프로젝트: zkj2012/minschant
import json
import requests
import rec
import baidu_voice
import os

# 调用百度asr,录入文字
rec.rec()
input_text = baidu_voice.get_asr('rec_temp.wav')

####################################
# 调用图灵机器人的接口,获得返回的值
####################################
query = {
            "reqType":0,
            "perception": {
                "inputText": {
                    "text": input_text
                },
                "inputImage": {
                    "url": "imageUrl"
                },
                "selfInfo": {
                    "location": {
                        "city": "",
                        "province": "",
                        "street": ""
                    }
                }
                                                                                        },
                                                                                        "userInfo": {
def main():
    photo_check = 1
    ticket_number = 0
    ticket_payment = 0
    ticket_lastprice = 0
    acceptable_prop = 0.57
    minimal_prob = 0.2
    grammatic_yes_no = ['tak', 'nie', 'powtórz']
    grammatic_one_two_three = ['Jeden', 'Dwa', 'Trzy', 'Powtórz']
    grammatic_one_two_three_f_f = [
        'Jeden', 'Dwa', 'Trzy', 'Cztery', 'Pięć', 'Powtórz'
    ]
    grammatic_one = [
        'Jeden',
        'Powtórz',
    ]

    grammatic_one_two = [
        'Jeden',
        'Dwa',
        'Powtórz',
    ]
    bool_1 = True
    bool_2 = False
    word_recognized = 0

    bool_opcja1 = False

    while (bool_1):

        if (bool_2 == False):
            playprompt.play_prompt("resources/dzien_dobry.WAV")  # powitanie
        else:
            playprompt.play_prompt(
                "resources/nie rozumiem krocej.WAV")  # powitanie
            bool_2 = False
        rec.rec(2)
        word_recognized = recognize.return_recognized("answer.wav",
                                                      grammatic_yes_no)
        if ((is_empty(word_recognized)) == False):
            for name in word_recognized:
                if (name.title() == "Tak"
                        and word_recognized[name] >= acceptable_prop):
                    bool_opcja1 = True
                    bool_1 = False

                elif (name.title() == "Nie"
                      and word_recognized[name] >= acceptable_prop):

                    bool_1 = False
                    return
                elif (name.title() == "Powtórz"
                      and word_recognized[name] >= acceptable_prop):
                    bool_1 = True
                elif (word_recognized[name] <= acceptable_prop
                      and word_recognized[name] >= minimal_prob):

                    bool_2 = True
                else:

                    bool_1 = False
                    return

        else:
            return

    bool_2 = False
    bool_opcja1 = False
    bool_opcja2 = False
    bool_opcja3 = False

    word_recognized.clear()

    print("wybor rodzaju biletu normalny/ulgowy/rodzinny")
    bool_powrot_1 = True  # zmienna ktora umozliwia zakup nastepnego bieltu

    while (bool_powrot_1):
        bool_1 = True
        while (bool_1):

            if (bool_2 == False):
                playprompt.play_prompt(
                    "resources/nor_ulg_rodz_krocej.WAV")  # powitanie
            else:
                playprompt.play_prompt(
                    "resources/nie rozumiem krocej.WAV")  # powitanie
                bool_2 = False
            rec.rec(2.5)
            word_recognized = recognize.return_recognized(
                "answer.wav", grammatic_one_two_three)
            if ((is_empty(word_recognized)) == False):
                for name in word_recognized:
                    if (name.title() == "Jeden"
                            and word_recognized[name] >= acceptable_prop):
                        bool_opcja1 = True
                        bool_1 = False

                    elif ((name.title() == "Dwa")
                          and word_recognized[name] >= acceptable_prop):
                        bool_opcja2 = True
                        bool_1 = False

                    elif ((name.title() == "Trzy")
                          and word_recognized[name] >= acceptable_prop):
                        bool_opcja3 = True
                        bool_1 = False

                    elif (name.title() == "Powtórz"
                          and word_recognized[name] >= acceptable_prop):
                        bool_1 = True
                    elif (word_recognized[name] >= minimal_prob):

                        bool_2 = True
                    else:

                        bool_1 = False
                        return
            else:
                if (photo_check == 1):
                    bool_2 = True

                else:
                    bool_1 = False
                    return

        bool_1 = True
        bool_2 = False

        word_recognized.clear()

        if (bool_opcja1 == True or bool_opcja2 == True):
            bool_split1 = True
            while (bool_1):

                if (bool_2 == False and bool_opcja1 == True):
                    playprompt.play_prompt(
                        "resources/normalny_ceny_krocej.WAV")
                elif (bool_2 == False and bool_opcja2 == True):
                    playprompt.play_prompt("resources/ulgowe_ceny_krocej.WAV")
                else:
                    playprompt.play_prompt("resources/nie rozumiem krocej.WAV")
                    bool_2 = False
                rec.rec(2.5)
                word_recognized = recognize.return_recognized(
                    "answer.wav", grammatic_one_two_three_f_f)
                if ((is_empty(word_recognized)) == False):
                    for name in word_recognized:
                        if (name.title() == "Jeden"
                                and word_recognized[name] >= acceptable_prop):

                            bool_1 = False
                            ticket_number += 1
                            if (bool_2 == False and bool_opcja1 == True):
                                ticket_payment += 2.8
                                ticket_lastprice = 2.8
                            elif (bool_2 == False and bool_opcja2 == True):
                                ticket_payment += 1.4
                                ticket_lastprice = 1.4
                            print("1")
                        elif (name.title() == "Dwa"
                              and word_recognized[name] >= acceptable_prop):
                            bool_1 = False
                            ticket_number += 1
                            if (bool_2 == False and bool_opcja1 == True):
                                ticket_payment += 3.8
                                ticket_lastprice = 3.8
                            elif (bool_2 == False and bool_opcja2 == True):
                                ticket_payment += 1.9
                                ticket_lastprice = 1.9
                            print("2")
                        elif (name.title() == "Trzy"
                              and word_recognized[name] >= acceptable_prop):
                            bool_1 = False
                            ticket_number += 1
                            if (bool_2 == False and bool_opcja1 == True):
                                ticket_payment += 5
                                ticket_lastprice = 5
                            elif (bool_2 == False and bool_opcja2 == True):
                                ticket_payment += 2.5
                                ticket_lastprice = 2.5
                            print("3")
                        elif (name.title() == "Cztery"
                              and word_recognized[name] >= acceptable_prop):
                            bool_1 = False
                            ticket_number += 1
                            if (bool_2 == False and bool_opcja1 == True):
                                ticket_payment += 7
                                ticket_lastprice = 7
                            elif (bool_2 == False and bool_opcja2 == True):
                                ticket_payment += 3
                                ticket_lastprice = 3
                            print("4")
                        elif (name.title() == "Pięć"
                              and word_recognized[name] >= acceptable_prop):
                            bool_1 = False
                            ticket_number += 1
                            if (bool_2 == False and bool_opcja1 == True):
                                ticket_payment += 14
                                ticket_lastprice = 14
                            elif (bool_2 == False and bool_opcja2 == True):
                                ticket_payment += 7.5
                                ticket_lastprice = 7.5

                        elif (name.title() == "Powtórz"
                              and word_recognized[name] >= acceptable_prop):
                            bool_1 = True
                        elif (word_recognized[name] >= minimal_prob):

                            bool_2 = True
                        else:

                            bool_1 = False
                            return

                else:
                    if (photo_check == 1):
                        bool_2 = True

                    else:
                        bool_1 = False
                        return
        elif (bool_opcja3 == True):
            while (bool_1):
                if (bool_2 == False and bool_opcja3 == True):
                    playprompt.play_prompt(
                        "resources/cena_rodzinny_krocej.WAV")
                else:
                    playprompt.play_prompt(
                        "resources/nie rozumiem krocej.WAV")  # powitanie
                    bool_2 = False
                rec.rec(2.5)
                word_recognized = recognize.return_recognized(
                    "answer.wav", grammatic_one)
                if ((is_empty(word_recognized)) == False):
                    for name in word_recognized:
                        if ((name.title() == "Jeden" or name.title() == "1")
                                and word_recognized[name] >= acceptable_prop):
                            bool_1 = False
                            ticket_number += 1
                            ticket_payment += 16
                            ticket_lastprice = 16

                        elif (name.title() == "Powtórz"
                              and word_recognized[name] >= acceptable_prop):
                            bool_1 = True
                        elif (word_recognized[name] >= minimal_prob):

                            bool_2 = True
                        else:

                            bool_1 = False
                            return
                else:
                    if (photo_check == 1):
                        bool_2 = True

                    else:
                        bool_1 = False
                        return

        bool_1 = True
        bool_2 = False
        bool_opcja1 = False
        bool_opcja2 = False
        bool_opcja3 = False

        while (bool_1):

            if (bool_2 == False):
                playprompt.play_prompt(
                    "resources/platnosc_usun_kup_krocej.WAV")  # powitanie
            else:
                playprompt.play_prompt("resources/nie rozumiem krocej.WAV")
                bool_2 = False
            rec.rec(2.5)
            word_recognized = recognize.return_recognized(
                "answer.wav", grammatic_one_two_three)
            if ((is_empty(word_recognized)) == False):
                for name in word_recognized:
                    if (name.title() == "Jeden"
                            and word_recognized[name] >= acceptable_prop):
                        if (ticket_number < 2):
                            bool_1 = False
                        else:
                            playprompt.play_prompt("resources/maxbilety.WAV")
                            bool_1 = False
                            bool_powrot_1 = False

                    elif ((name.title() == "Dwa")
                          and word_recognized[name] >= acceptable_prop):
                        bool_1 = False
                        bool_powrot_1 = False

                    elif ((name.title() == "Trzy")
                          and word_recognized[name] >= acceptable_prop):
                        bool_1 = False  # przechodzimy do pytania czy chce kupic nowy bilet po usunieciu
                        bool_opcja3 = True
                        ticket_number -= 1

                    elif (name.title() == "Powtórz"
                          and word_recognized[name] >= acceptable_prop):
                        bool_1 = True
                    elif (word_recognized[name] >= minimal_prob):

                        bool_2 = True
                    else:

                        bool_1 = False
                        return
            else:
                if (photo_check == 1):
                    bool_2 = True

                else:
                    bool_1 = False
                    return

        while (bool_opcja3):

            if (bool_2 == False):
                playprompt.play_prompt("resources/usunieto_bilet_krocej.WAV")
                # powitanie
            else:
                playprompt.play_prompt("resources/nie rozumiem krocej.WAV")
                bool_2 = False  # powitanie
            rec.rec(2.5)
            word_recognized = recognize.return_recognized(
                "answer.wav", grammatic_yes_no)
            if ((is_empty(word_recognized)) == False):
                for name in word_recognized:
                    if (name.title() == "Tak"
                            and word_recognized[name] >= acceptable_prop):
                        ticket_payment = ticket_payment - ticket_lastprice
                        #print(ticket_payment)
                        bool_opcja3 = False
                        print("1")
                    elif ((name.title() == "Nie")
                          and word_recognized[name] >= acceptable_prop):
                        ticket_payment = ticket_payment - ticket_lastprice
                        #print(ticket_payment)
                        if (ticket_number == 0):
                            playprompt.play_prompt("resources/dziekujemy.WAV")
                            return
                        else:
                            bool_powrot_1 = False
                            bool_opcja3 = False

                    elif (name.title() == "Powtórz"
                          and word_recognized[name] >= acceptable_prop):
                        bool_opcja3 = True
                    elif (word_recognized[name] >= minimal_prob):
                        bool_2 = True
                    else:
                        bool_opcja3 = False
                        return
            else:
                if (photo_check == 1):
                    bool_2 = True

                else:
                    bool_1 = False
                    return

    bool_powrot2 = True
    bool_1 = True
    bool_opcja1 = False
    bool_opcja2 = False

    while (bool_powrot2):
        while (bool_1):

            if (bool_2 == False):
                playprompt.play_prompt(
                    "resources/platnosc_karta_gotowka_krocej.WAV")  # powitanie
            else:
                playprompt.play_prompt("resources/nie rozumiem krocej.WAV")
                bool_2 = False  # powitanie
            rec.rec(2.5)
            word_recognized = recognize.return_recognized(
                "answer.wav", grammatic_one_two)
            if ((is_empty(word_recognized)) == False):
                for name in word_recognized:
                    if (name.title() == "Jeden"
                            and word_recognized[name] >= acceptable_prop):
                        bool_1 = False
                        bool_opcja1 = True
                        print("1")
                    elif ((name.title() == "Dwa")
                          and word_recognized[name] >= acceptable_prop):
                        bool_1 = False
                        bool_opcja2 = True  # randint(a,b)
                        print("2")
                    elif (name.title() == "Powtórz"
                          and word_recognized[name] >= acceptable_prop):
                        bool_1 = True
                    elif (word_recognized[name] >= minimal_prob):
                        bool_2 = True
                    else:
                        bool_1 = False
                        return
            else:
                if (photo_check == 1):
                    bool_2 = True

                else:
                    bool_1 = False
                    return

        trans_state = 1
        if bool_opcja1 == True:
            # print(ticket_payment)
            unity, dozens = price(ticket_payment)
            # print(unity)

            pathunity = "resources/unity/" + unity
            pathdozens = "resources/dozens/" + dozens
            #print(pathunity)
            #print(pathdozens)
            playprompt.play_prompt("resources/kwota.WAV")

            playprompt.play_prompt(pathunity)
            if (dozens != '.wav'):
                playprompt.play_prompt(pathdozens)
            playprompt.play_prompt("resources/pln.WAV")
            playprompt.play_prompt("resources/glosnik_karta_krocej.WAV")
            playprompt.play_prompt("resources/muzyczka_1.WAV")
            time.sleep(random.randint(3, 6))
            trans_state = random.randint(1, 2)

        elif bool_opcja2 == True:
            # print(ticket_payment)
            unity, dozens = price(ticket_payment)
            # print(unity)

            pathunity = "resources/unity/" + unity
            pathdozens = "resources/dozens/" + dozens
            # print(pathunity)
            # print(pathdozens)
            playprompt.play_prompt("resources/kwota.WAV")

            playprompt.play_prompt(pathunity)
            if (dozens != '.wav'):
                playprompt.play_prompt(pathdozens)
            playprompt.play_prompt("resources/pln.WAV")

            playprompt.play_prompt("resources/glosnik_monety_krocej.WAV")
            playprompt.play_prompt("resources/muzyczka_1.WAV")
            time.sleep(
                10
            )  # oczekauje na monety i fotokomorka sprawdza czy klient dalej stoi przy automacie
            trans_state = random.randint(1, 2)

        if (bool_opcja1 == True and trans_state == 1):
            if (bool_opcja1 == True):
                playprompt.play_prompt("resources/transakcja_udana_karta.WAV")
            else:
                playprompt.play_prompt("resources/reszta_bilet_krocej.WAV")
            playprompt.play_prompt("resources/dziekujemy.WAV")
            return
        elif ((bool_opcja1 == True and trans_state == 2)):
            playprompt.play_prompt("resources/trans_nieudana.WAV")
            playprompt.play_prompt("resources/dziekujemy.WAV")
            return
        else:
            playprompt.play_prompt("resources/reszta_bilet_krocej.WAV")
            playprompt.play_prompt("resources/dziekujemy.WAV")
            return
    return
예제 #15
0
from crontab import CronTab
import subprocess as sub
from speak import speak
from rec import rec
import parseSTT
import processSTT
import re


cron = CronTab(user='******')
while True:
	speak("When do you want the alarm for?")
	empty=rec(5)
	if not empty:
		for line in open("stt.txt",'r'):
			time = re.compile("[0-9]+\shours?\s[0-9]+\sminutes?\sp\.?m\.?|a\.?m\.?")	
			if time.search(line):
				print line			
				words = line.split(" ")
				hr = words[0]
				min = words[2]
				period = words[4]
				speak("alarm will be set for "+hr+":"+min+" "+period)
				if re.search("p\.?m\.?",period):
					hr=str(int(hr)+12)
				job=cron.new(command="sudo /home/pi/Room/commands/alarm.sh")
				job.minute.on(min)
				job.hour.on(hr)
				job.enable()
				cron.write()
				quit()
import subprocess as sub
from speak import speak
from rec import rec
import parseSTT
import processSTT
import re

while True:
	speak("When do you want the alarm for?")
	silent=rec(6)
	if not silent:
		parseSTT.parse()
		file = open("./stt.txt",'r')
		for line in file:
			print line
			if re.search("[0-9]+\shours\s[0-9]+\sminutes",line):
				words=line.split(" ")
				hr=words[0]
				min=words[2]
			print hr,min,period
			speak("alarm will be set for"+line)
			cmd="(crontab -l ; echo "+min+" "+hr+" * * * ~/Room/commands/alarm.sh) | sort - | uniq - | crontab -"
			print cmd
			sub.call(cmd,shell=True)
			quit()
		speak("sorry, I did not hear any valid times. try again")