<commit_before>package org.cocolab.inpro.apps;

import java.io.IOException;
import java.net.URL;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.UnsupportedAudioFileException;

import org.cocolab.inpro.audio.AudioUtils;
import org.cocolab.inpro.sphinx.frontend.RtpRecvProcessor;

import edu.cmu.sphinx.frontend.FrontEnd;
import edu.cmu.sphinx.frontend.util.Microphone;
import edu.cmu.sphinx.frontend.util.StreamDataSource;
import edu.cmu.sphinx.recognizer.Recognizer;
import edu.cmu.sphinx.result.Result;
import edu.cmu.sphinx.util.props.ConfigurationManager;
import edu.cmu.sphinx.util.props.PropertyException;

public class SimpleReco {

	protected static void setupSource(ConfigurationManager cm, CommandLineParser clp) throws InstantiationException, PropertyException, UnsupportedAudioFileException, IOException {
    	FrontEnd fe = (FrontEnd) cm.lookup("frontend");
		switch (clp.getInputMode()) {
			case CommandLineParser.MICROPHONE_INPUT:
				Microphone mic = (Microphone) cm.lookup("microphone");
				FrontEnd endpoint = (FrontEnd) cm.lookup("endpointing");
				endpoint.setPredecessor(mic);
				endpoint.initialize();
				mic.initialize();
				fe.setPredecessor(endpoint);
				if (!mic.startRecording()) {
					System.err.println("Could not open microphone. Exiting...");
					System.exit(1);
				}
			break;
			case CommandLineParser.RTP_INPUT:
				RtpRecvProcessor rtp = (RtpRecvProcessor) cm.lookup("RTPDataSource");
				cm.setProperty("RTPDataSource",	"recvPort", "" + clp.rtpPort);
				rtp.initialize();
				endpoint = (FrontEnd) cm.lookup("endpointing");
				endpoint.setPredecessor(rtp);
				endpoint.initialize();
				fe.setPredecessor(endpoint);
			break;
			case CommandLineParser.FILE_INPUT:
				StreamDataSource sds = (StreamDataSource) cm.lookup("streamDataSource");
				sds.initialize();
				fe.setPredecessor(sds);
				URL audioURL = clp.getAudioURL();
				AudioInputStream ais = AudioUtils.getAudioStreamForURL(audioURL);
	            sds.setInputStream(ais, audioURL.getFile());
			break;
		}
	}

	private static void setupMonitors(ConfigurationManager cm, CommandLineParser clp) throws InstantiationException, PropertyException {
		if ((clp.getOutputMode() & CommandLineParser.OAA_OUTPUT) == CommandLineParser.OAA_OUTPUT) {
			cm.lookup("newWordNotifierAgent");
		}
		if ((clp.getOutputMode() & CommandLineParser.TED_OUTPUT) == CommandLineParser.TED_OUTPUT) {
			cm.lookup("TEDviewNotifier");
		}
		if ((clp.getOutputMode() & CommandLineParser.LABEL_OUTPUT) == CommandLineParser.LABEL_OUTPUT) {
			cm.lookup("labelWriter");
		}
		if (clp.verbose()) {
			cm.lookup("memoryTracker");
			cm.lookup("speedTracker");
		}
	}

	public static void main(String[] args) throws IOException, PropertyException, InstantiationException, UnsupportedAudioFileException {
    	CommandLineParser clp = new CommandLineParser(args);
    	if (!clp.parsedSuccessfully()) { System.exit(1); }
    	ConfigurationManager cm = new ConfigurationManager(clp.getConfigURL());
    	System.err.println("Loading recognizer...\n");
    	Recognizer recognizer = (Recognizer) cm.lookup("recognizer");
    	recognizer.allocate();<commit_msg>write name of processed file to STDERR<commit_after>package org.cocolab.inpro.apps;

import java.io.IOException;
import java.net.URL;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.UnsupportedAudioFileException;

import org.cocolab.inpro.audio.AudioUtils;
import org.cocolab.inpro.sphinx.frontend.RtpRecvProcessor;

import edu.cmu.sphinx.frontend.FrontEnd;
import edu.cmu.sphinx.frontend.util.Microphone;
import edu.cmu.sphinx.frontend.util.StreamDataSource;
import edu.cmu.sphinx.recognizer.Recognizer;
import edu.cmu.sphinx.result.Result;
import edu.cmu.sphinx.util.props.ConfigurationManager;
import edu.cmu.sphinx.util.props.PropertyException;

public class SimpleReco {

	protected static void setupSource(ConfigurationManager cm, CommandLineParser clp) throws InstantiationException, PropertyException, UnsupportedAudioFileException, IOException {
    	FrontEnd fe = (FrontEnd) cm.lookup("frontend");
		switch (clp.getInputMode()) {
			case CommandLineParser.MICROPHONE_INPUT:
				Microphone mic = (Microphone) cm.lookup("microphone");
				FrontEnd endpoint = (FrontEnd) cm.lookup("endpointing");
				endpoint.setPredecessor(mic);
				endpoint.initialize();
				mic.initialize();
				fe.setPredecessor(endpoint);
				if (!mic.startRecording()) {
					System.err.println("Could not open microphone. Exiting...");
					System.exit(1);
				}
			break;
			case CommandLineParser.RTP_INPUT:
				RtpRecvProcessor rtp = (RtpRecvProcessor) cm.lookup("RTPDataSource");
				cm.setProperty("RTPDataSource",	"recvPort", "" + clp.rtpPort);
				rtp.initialize();
				endpoint = (FrontEnd) cm.lookup("endpointing");
				endpoint.setPredecessor(rtp);
				endpoint.initialize();
				fe.setPredecessor(endpoint);
			break;
			case CommandLineParser.FILE_INPUT:
				StreamDataSource sds = (StreamDataSource) cm.lookup("streamDataSource");
				sds.initialize();
				fe.setPredecessor(sds);
				URL audioURL = clp.getAudioURL();
				System.err.println("input from " + audioURL.toString() + "\n");
				AudioInputStream ais = AudioUtils.getAudioStreamForURL(audioURL);
	            sds.setInputStream(ais, audioURL.getFile());
			break;
		}
	}

	private static void setupMonitors(ConfigurationManager cm, CommandLineParser clp) throws InstantiationException, PropertyException {
		if ((clp.getOutputMode() & CommandLineParser.OAA_OUTPUT) == CommandLineParser.OAA_OUTPUT) {
			cm.lookup("newWordNotifierAgent");
		}
		if ((clp.getOutputMode() & CommandLineParser.TED_OUTPUT) == CommandLineParser.TED_OUTPUT) {
			cm.lookup("TEDviewNotifier");
		}
		if ((clp.getOutputMode() & CommandLineParser.LABEL_OUTPUT) == CommandLineParser.LABEL_OUTPUT) {
			cm.lookup("labelWriter");
		}
		if (clp.verbose()) {
			cm.lookup("memoryTracker");
			cm.lookup("speedTracker");
		}
	}

	public static void main(String[] args) throws IOException, PropertyException, InstantiationException, UnsupportedAudioFileException {
    	CommandLineParser clp = new CommandLineParser(args);
    	if (!clp.parsedSuccessfully()) { System.exit(1); }
    	ConfigurationManager cm = new ConfigurationManager(clp.getConfigURL());
    	System.err.println("Loading recognizer...\n");
    	Recognizer recognizer = (Recognizer) cm.lookup("recognizer");
    	recognizer.allocate();
{'fraction_non_alphanumeric': 0.12252224129857968, 'fraction_numerical': 0.0006243171531137818, 'mean_word_length': 5.0452830188679245, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1073048', 'n_tokens_mistral': 2223, 'n_tokens_neox': 1993, 'n_words': 335}