TTSConfig.java
2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.xly.tts.config;
import lombok.Data;
import okhttp3.ConnectionPool;
import okhttp3.Dispatcher;
import okhttp3.OkHttpClient;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.concurrent.TimeUnit;
@Data
@Configuration
@ConfigurationProperties(prefix = "tts")
public class TTSConfig {
private PythonService python = new PythonService();
private CommandLine commandLine = new CommandLine();
private OkHttpConfig okHttp = new OkHttpConfig();
@Data
public static class PythonService {
private boolean enabled = true;
private String url = "http://127.0.0.1:8000";
private int timeout = 30000;
}
@Data
public static class CommandLine {
private boolean enabled = false;
private String pythonPath = "python";
private int bufferSize = 4096;
}
@Data
public static class OkHttpConfig {
private int connectTimeout = 30;
private int readTimeout = 60;
private int writeTimeout = 60;
private int maxRequests = 64;
private int maxRequestsPerHost = 32;
private int maxIdleConnections = 5;
private long keepAliveDuration = 5;
}
@Bean
public OkHttpClient okHttpClient() {
Dispatcher dispatcher = new Dispatcher();
dispatcher.setMaxRequests(okHttp.getMaxRequests());
dispatcher.setMaxRequestsPerHost(okHttp.getMaxRequestsPerHost());
ConnectionPool connectionPool = new ConnectionPool(
okHttp.getMaxIdleConnections(),
okHttp.getKeepAliveDuration(),
TimeUnit.MINUTES
);
return new OkHttpClient.Builder()
.dispatcher(dispatcher)
.connectionPool(connectionPool)
.connectTimeout(okHttp.getConnectTimeout(), TimeUnit.SECONDS)
.readTimeout(okHttp.getReadTimeout(), TimeUnit.SECONDS)
.writeTimeout(okHttp.getWriteTimeout(), TimeUnit.SECONDS)
.retryOnConnectionFailure(true)
.build();
}
}