1   package org.daisy.pipeline.tts;
2   
3   import java.util.Map;
4   
5   /**
6    * Classes that implements the TTSService interface are meant to be allocated
7    * only once, as opposed to TTSEngines. The main role of TTSService is to
8    * allocate TTSEngines depending on given parameters.
9    * 
10   */
11  public interface TTSService {
12  
13  	class SynthesisException extends Exception {
14  
15  		public SynthesisException(String message, Throwable cause) {
16  			super(message, cause);
17  		}
18  
19  		public SynthesisException(Throwable t) {
20  			super(t);
21  		}
22  
23  		public SynthesisException(String message) {
24  			super(message);
25  		}
26  	}
27  
28  	class ServiceDisabledException extends Exception {
29  
30  		public ServiceDisabledException() {
31  			super();
32  		}
33  
34  		public ServiceDisabledException(Throwable t) {
35  			super(t);
36  		}
37  
38  		public ServiceDisabledException(String message) {
39  			super(message);
40  		}
41  
42  		public ServiceDisabledException(String message, Throwable cause) {
43  			super(message, cause);
44  		}
45  	}
46  
47  	/**
48  	 * Allocate a new TTSEngine
49  	 * 
50  	 * @param params contains various key-value pairs. Some of them might be options
51  	 *         for the TTS processor under consideration, e.g. server IPs,
52  	 *         priorities or sound quality. It can also contain options which
53  	 *         have nothing to do with the returned TTSEngine. Such options must
54  	 *         be ignored. This method is allowed to perform heavy
55  	 *         initializations as long as they can be interrupted with the
56  	 *         regular Java thread interruption mechanism. In particular, it is
57  	 *         not recommended to test a full text-to-speech step in this
58  	 *         method.
59  	 * @throws ServiceDisabledException if the service is not available, e.g. because
60  	 *         it was disabled by the user, or because required configuration is
61  	 *         missing.
62  	 * @throws Throwable if an engine could not be allocated for another reason.
63  	 */
64  	public TTSEngine newEngine(Map<String, String> params) throws ServiceDisabledException, Throwable;
65  
66  	/**
67  	 * @return the same name as in the CSS voice-family property. If several TTS
68  	 *         services share the same name, then the one with the highest
69  	 *         priority will be chosen. Must be thread-safe.
70  	 */
71  	public String getName();
72  
73  	/**
74  	 * @return a nice name for displaying in user interfaces.
75  	 */
76  	public default String getDisplayName() {
77  		return getName();
78  	}
79  }