src/main/java/ca/phon/plugins/praat/export/TextGridExporter.java
/**
	 * Create text grid for the specified session with given name.
	 *
	 * @param session
	 * @param recordFilter
	 * @param exports
	 * @param name
	 * @param appendTiers if a TextGrid already exists at <code>file</code> add
	 *  tiers to the existing TextGrid
	 *
	 * @throws IOException
	 * @throws InvalidHeaderException 
	 * @throws UnsupportedFormatException 
	 */
Create text grid for the specified session with given name.


Create text grid for the specified session with given name .
public void generateTextGrid(Project project, Session session, RecordFilter recordFilter,
			List<TextGridExportEntry> exports, File file, boolean appendTiers) throws IOException, UnsupportedFormatException, InvalidHeaderException {
		final File audioFile = getAudioFile(project, session);
		if(audioFile == null) throw new IOException("Unable to open audio");
		final Sampled sampled = new AudioFileSampled(AudioIO.openAudioFile(audioFile));
		if(sampled.getLength() == 0) throw new IOException("Unable to read audio file");
		final TextGridManager manager = new TextGridManager(project);
		final AtomicReference<TextGrid> textGridRef = new AtomicReference<TextGrid>(null);
		if(file.exists() && appendTiers) {
			textGridRef.set(TextGridManager.loadTextGrid(file));
		} else {
			try {
				textGridRef.set(TextGrid.createWithoutTiers(0.0, (double)sampled.getLength()));
			} catch (PraatException e) {
				throw new IOException(e);
			}
		}
		try {
			setupTextGridTiers(textGridRef.get(), exports);
			for(Record record:session.getRecords()) {
				if(recordFilter != null && !recordFilter.checkRecord(record)) continue;
				exports.forEach( (TextGridExportEntry entry) -> {
					addTierToTextGrid(record, textGridRef.get(), entry);
				} );
			}
			for(int tierIdx = 1; tierIdx <= textGridRef.get().numberOfTiers(); tierIdx++) {
				try {
					final IntervalTier intervalTier =
							textGridRef.get().checkSpecifiedTierIsIntervalTier(tierIdx);
					final TextInterval lastInterval =
							(intervalTier.numberOfIntervals() > 0 ? intervalTier.interval(intervalTier.numberOfIntervals()) : null);
					double lastIntervalStart =
							(lastInterval != null ? lastInterval.getXmax() : 0.0);
					double lastIntervalEnd = intervalTier.getXmax();
					if(lastIntervalStart < lastIntervalEnd) {
						intervalTier.addInterval(lastIntervalStart, lastIntervalEnd, "");
					}
				} catch (PraatException e) {
				}
			}
			TextGridManager.saveTextGrid(textGridRef.get(), file);
		} catch (PraatException pe) {
			throw new IOException(pe);
		}
	}
public void generateTextGrid ( Project project , Session session , RecordFilter recordFilter , List < TextGridExportEntry > exports , File file , boolean appendTiers ) throws IOException , UnsupportedFormatException , InvalidHeaderException { final File audioFile = getAudioFile ( project , session ) ; if ( audioFile == null ) throw new IOException ( "Unable to open audio" ) ; final Sampled sampled = new AudioFileSampled ( AudioIO . openAudioFile ( audioFile ) ) ; if ( sampled . getLength ( ) == 0 ) throw new IOException ( "Unable to read audio file" ) ; final TextGridManager manager = new TextGridManager ( project ) ; final AtomicReference < TextGrid > textGridRef = new AtomicReference < TextGrid > ( null ) ; if ( file . exists ( ) && appendTiers ) { textGridRef . set ( TextGridManager . loadTextGrid ( file ) ) ; } else { try { textGridRef . set ( TextGrid . createWithoutTiers ( 0.0 , ( double ) sampled . getLength ( ) ) ) ; } catch ( PraatException e ) { throw new IOException ( e ) ; } } try { setupTextGridTiers ( textGridRef . get ( ) , exports ) ; for ( Record record : session . getRecords ( ) ) { if ( recordFilter != null && ! recordFilter . checkRecord ( record ) ) continue ; exports . forEach ( ( TextGridExportEntry entry ) -> { addTierToTextGrid ( record , textGridRef . get ( ) , entry ) ; } ) ; } for ( int tierIdx = 1 ; tierIdx <= textGridRef . get ( ) . numberOfTiers ( ) ; tierIdx ++ ) { try { final IntervalTier intervalTier = textGridRef . get ( ) . checkSpecifiedTierIsIntervalTier ( tierIdx ) ; final TextInterval lastInterval = ( intervalTier . numberOfIntervals ( ) > 0 ? intervalTier . interval ( intervalTier . numberOfIntervals ( ) ) : null ) ; double lastIntervalStart = ( lastInterval != null ? lastInterval . getXmax ( ) : 0.0 ) ; double lastIntervalEnd = intervalTier . getXmax ( ) ; if ( lastIntervalStart < lastIntervalEnd ) { intervalTier . addInterval ( lastIntervalStart , lastIntervalEnd , "" ) ; } } catch ( PraatException e ) { } } TextGridManager . saveTextGrid ( textGridRef . get ( ) , file ) ; } catch ( PraatException pe ) { throw new IOException ( pe ) ; } }
Create text grid for the specified session with given name.
Create text grid for the specified session with given name .
// get audio file // ignore