Пример #1
0
void detect_cdimage(SECTION *section, int level)
{
  int mode, off;
  unsigned char *buf;
  SOURCE *s;

  if (get_buffer(section, 0, 2352, (void **)&buf) < 2352)
    return;

  /* check sync bytes as signature */
  if (memcmp(buf, syncbytes, 12) != 0)
    return;

  /* get mode of the track -- this determines sector layout */
  mode = buf[15];
  if (mode == 1) {
    /* standard data track */
    print_line(level, "Raw CD image, Mode 1");
    off = 16;
  } else if (mode == 2) {
    /* free-form track, assume XA form 1 */
    print_line(level, "Raw CD image, Mode 2, assuming Form 1");
    off = 24;
  } else
    return;

  /* create and analyze wrapped source */
  s = init_cdimage_source(section->source, section->pos + off);
  analyze_source(s, level);
  close_source(s);

  /* don't run other analyzers */
  stop_detect();
}
Пример #2
0
/*! function to feed audio to the ASR */
static switch_status_t pocketsphinx_asr_feed(switch_asr_handle_t *ah, void *data, unsigned int len, switch_asr_flag_t *flags)
{
	pocketsphinx_t *ps = (pocketsphinx_t *) ah->private_info;
	int rv = 0;

	if (switch_test_flag(ah, SWITCH_ASR_FLAG_CLOSED))
		return SWITCH_STATUS_BREAK;

	if (!switch_test_flag(ps, PSFLAG_HAS_TEXT) && switch_test_flag(ps, PSFLAG_READY)) {
		if (stop_detect(ps, (int16_t *) data, len / 2)) {
			char const *hyp;

			switch_mutex_lock(ps->flag_mutex);
			if ((hyp = ps_get_hyp(ps->ps, &ps->score, &ps->uttid))) {
				if (!zstr(hyp)) {
					ps_end_utt(ps->ps);
					switch_clear_flag(ps, PSFLAG_READY);
					if ((hyp = ps_get_hyp(ps->ps, &ps->score, &ps->uttid))) {
						if (zstr(hyp)) {
							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Lost the text, never mind....\n");
							ps_start_utt(ps->ps, NULL);
							switch_set_flag(ps, PSFLAG_READY);
						} else {
							ps->hyp = switch_core_strdup(ah->memory_pool, hyp);
							switch_set_flag(ps, PSFLAG_HAS_TEXT);
						}
					}
				}
			}
			switch_mutex_unlock(ps->flag_mutex);
		}

		/* only feed ps_process_raw when we are listening */
		if (ps->listening) {
			switch_mutex_lock(ps->flag_mutex);
			rv = ps_process_raw(ps->ps, (int16 *) data, len / 2, FALSE, FALSE);
			switch_mutex_unlock(ps->flag_mutex);
		}

		if (rv < 0) {
			return SWITCH_STATUS_FALSE;
		}
	}

	return SWITCH_STATUS_SUCCESS;
}
Пример #3
0
/*! function to feed audio to the ASR */
static switch_status_t pocketsphinx_asr_feed(switch_asr_handle_t *ah, void *data, unsigned int len, switch_asr_flag_t *flags)
{
	pocketsphinx_t *ps = (pocketsphinx_t *) ah->private_info;
	int rv = 0;

	if (switch_test_flag(ah, SWITCH_ASR_FLAG_CLOSED))
		return SWITCH_STATUS_BREAK;

	if (!switch_test_flag(ps, PSFLAG_NOMATCH) && !switch_test_flag(ps, PSFLAG_NOINPUT) && !switch_test_flag(ps, PSFLAG_HAS_TEXT) && switch_test_flag(ps, PSFLAG_READY)) {
		if (stop_detect(ps, (int16_t *) data, len / 2)) {
			char const *hyp;

			switch_mutex_lock(ps->flag_mutex);
			if ((hyp = ps_get_hyp(ps->ps, &ps->score, &ps->uttid))) {
				if (!zstr(hyp)) {
					ps_end_utt(ps->ps);
					switch_clear_flag(ps, PSFLAG_READY);
					if ((hyp = ps_get_hyp(ps->ps, &ps->score, &ps->uttid))) {
						if (zstr(hyp)) {
							if (!switch_test_flag(ps, PSFLAG_SPEECH_TIMEOUT)) {
								switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Lost the text, never mind....\n");
								ps_start_utt(ps->ps, NULL);
								switch_set_flag(ps, PSFLAG_READY);
							}
						} else {
							/* get match and confidence */
							int32_t conf;

							conf = ps_get_prob(ps->ps, &ps->uttid);

							ps->confidence = (conf + 20000) / 200;

							if (ps->confidence < 0) {
								ps->confidence = 0;
							}

							if (ps->confidence_threshold <= 0 || ps->confidence >= ps->confidence_threshold) {
								ps->hyp = switch_core_strdup(ah->memory_pool, hyp);
								switch_set_flag(ps, PSFLAG_HAS_TEXT);
							} else {
								/* have match, but below confidence threshold */
								switch_set_flag(ps, PSFLAG_NOMATCH);
							}
						}
					}
				}
			}
			if (switch_test_flag(ps, PSFLAG_SPEECH_TIMEOUT) && !switch_test_flag(ps, PSFLAG_HAS_TEXT)) {
				/* heard something, but doesn't match anything */
				switch_clear_flag(ps, PSFLAG_READY);
				switch_set_flag(ps, PSFLAG_NOMATCH);
			}
			switch_mutex_unlock(ps->flag_mutex);
		}

		/* only feed ps_process_raw when we are listening */
		if (ps->listening) {
			switch_mutex_lock(ps->flag_mutex);
			rv = ps_process_raw(ps->ps, (int16 *) data, len / 2, FALSE, FALSE);
			switch_mutex_unlock(ps->flag_mutex);
		}

		if (rv < 0) {
			return SWITCH_STATUS_FALSE;
		}
	} else if (switch_test_flag(ps, PSFLAG_NOINPUT_TIMEOUT)) {
		/* never heard anything */
		switch_clear_flag_locked(ps, PSFLAG_READY);
	}

	return SWITCH_STATUS_SUCCESS;
}
Пример #4
0
/*! function to feed audio to the ASR */
static switch_status_t pocketsphinx_asr_feed(switch_asr_handle_t *ah, void *data, unsigned int len, switch_asr_flag_t *flags)
{
	pocketsphinx_t *ps = (pocketsphinx_t *) ah->private_info;
	int rv = 0;
    int ret = MSP_SUCCESS;
    int errcode = MSP_SUCCESS;
    
    //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, ">>>>>>>>pocketsphinx_asr_feed<<<<<<<<<\n");


	if (switch_test_flag(ah, SWITCH_ASR_FLAG_CLOSED))
		return SWITCH_STATUS_BREAK;

	if (!switch_test_flag(ps, PSFLAG_NOMATCH) && !switch_test_flag(ps, PSFLAG_NOINPUT) && !switch_test_flag(ps, PSFLAG_HAS_TEXT) && switch_test_flag(ps, PSFLAG_READY)) {
		if (stop_detect(ps, (int16_t *) data, len / 2)) {
                    
			char const *hyp;

			switch_mutex_lock(ps->flag_mutex);
            
            QISRAudioWrite(ps->ifly_session_id, NULL, 0, MSP_AUDIO_SAMPLE_LAST, &(ps->ifly_ep_stat), &(ps->ifly_rec_stat));
            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, ">>>>>>>> tell zero <<<<<<<<<\n");

            hyp = QISRGetResult(ps->ifly_session_id, &(ps->ifly_rec_stat), 0, &errcode);
            
            
            
            if (hyp || ps->ifly_rec_stat != MSP_REC_STATUS_INCOMPLETE) {
                ps->ifly_wait_result = SWITCH_FALSE;
            }
            
			if (hyp) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, ">>>>>>>> k0<<<<<<<<<\n");

				if (errcode == MSP_SUCCESS && !zstr(hyp)) {
                    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, ">>>>>>>> k2<<<<<<<<<\n");

					switch_clear_flag(ps, PSFLAG_READY);
					ps->hyp = switch_core_strdup(ah->memory_pool, hyp);
					switch_set_flag(ps, PSFLAG_HAS_TEXT);
					
				}
			} 
            
			if (switch_test_flag(ps, PSFLAG_SPEECH_TIMEOUT) && !switch_test_flag(ps, PSFLAG_HAS_TEXT)) {
				/* heard something, but doesn't match anything */
				switch_clear_flag(ps, PSFLAG_READY);
				switch_set_flag(ps, PSFLAG_NOMATCH);
			}
			switch_mutex_unlock(ps->flag_mutex);
            
		} else if (  ps->ifly_wait_result == SWITCH_TRUE ) {
            
			char const *hyp;
            switch_mutex_lock(ps->flag_mutex);
            hyp = QISRGetResult(ps->ifly_session_id, &(ps->ifly_rec_stat), 0, &errcode);

            if (hyp || ps->ifly_rec_stat != MSP_REC_STATUS_INCOMPLETE) {
                ps->ifly_wait_result = SWITCH_FALSE;
            }
            
            if (hyp) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, ">>>>>>>> k0<<<<<<<<<\n");

				if (errcode == MSP_SUCCESS && !zstr(hyp)) {
                   switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, ">>>>>>>> k2<<<<<<<<<\n");

					switch_clear_flag(ps, PSFLAG_READY);
                    
					ps->hyp = switch_core_strdup(ah->memory_pool, hyp);
					switch_set_flag(ps, PSFLAG_HAS_TEXT);
					
				}
			} 
            
            switch_mutex_unlock(ps->flag_mutex);

        }

		/* only feed ps_process_raw when we are listening */
		if (ps->listening) {
			switch_mutex_lock(ps->flag_mutex);
			//rv = ps_process_raw(ps->ps, (int16 *) data, len / 2, FALSE, FALSE);
            
            /* chenbingfeng*/
            ret = QISRAudioWrite(ps->ifly_session_id, (const void *)data, len, ps->ifly_aud_stat, &(ps->ifly_ep_stat), &(ps->ifly_rec_stat));
		    if (MSP_SUCCESS != ret)
		    {
			    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "\nQISRAudioWrite failed! error code:%d\n", ret);
		    }
            
            
			switch_mutex_unlock(ps->flag_mutex);
		}

		if (rv < 0) {
			return SWITCH_STATUS_FALSE;
		}
	} else if (switch_test_flag(ps, PSFLAG_NOINPUT_TIMEOUT)) {
		/* never heard anything */
		switch_clear_flag_locked(ps, PSFLAG_READY);
	}

	return SWITCH_STATUS_SUCCESS;
}