You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Add comprehensive migration guide with find/replace patterns
- Include side-by-side code examples (old vs new API)
- Add provider-agnostic usage examples and best practices
- Document breaking changes in 1.1.0-RC1 upgrade notes
One of the key benefits of the shared TTS interfaces is the ability to write code that works with any TTS provider without modification. The actual provider (OpenAI, ElevenLabs, etc.) is determined by your Spring Boot configuration, allowing you to switch providers without changing application code.
93
+
94
+
=== Basic Service Example
91
95
92
96
The shared interfaces allow you to write code that works with any TTS provider:
93
97
@@ -103,6 +107,7 @@ public class NarrationService {
103
107
}
104
108
105
109
public byte[] narrate(String text) {
110
+
// Works with any TTS provider
106
111
return textToSpeechModel.call(text);
107
112
}
108
113
@@ -116,6 +121,214 @@ public class NarrationService {
116
121
117
122
This service works seamlessly with OpenAI, ElevenLabs, or any other TTS provider, with the actual implementation determined by your Spring Boot configuration.
118
123
124
+
=== Advanced Example: Multi-Provider Support
125
+
126
+
You can build applications that support multiple TTS providers simultaneously:
127
+
128
+
[source,java]
129
+
----
130
+
@Service
131
+
public class MultiProviderNarrationService {
132
+
133
+
private final Map<String, TextToSpeechModel> providers;
134
+
135
+
public MultiProviderNarrationService(List<TextToSpeechModel> models) {
136
+
// Spring will inject all available TextToSpeechModel beans
137
+
this.providers = models.stream()
138
+
.collect(Collectors.toMap(
139
+
model -> model.getClass().getSimpleName(),
140
+
model -> model
141
+
));
142
+
}
143
+
144
+
public byte[] narrateWithProvider(String text, String providerName) {
145
+
TextToSpeechModel model = providers.get(providerName);
146
+
if (model == null) {
147
+
throw new IllegalArgumentException("Unknown provider: " + providerName);
148
+
}
149
+
return model.call(text);
150
+
}
151
+
152
+
public Set<String> getAvailableProviders() {
153
+
return providers.keySet();
154
+
}
155
+
}
156
+
----
157
+
158
+
=== Streaming Audio Example
159
+
160
+
The shared interfaces also support streaming for real-time audio generation:
161
+
162
+
[source,java]
163
+
----
164
+
@Service
165
+
public class StreamingNarrationService {
166
+
167
+
private final TextToSpeechModel textToSpeechModel;
168
+
169
+
public StreamingNarrationService(TextToSpeechModel textToSpeechModel) {
170
+
this.textToSpeechModel = textToSpeechModel;
171
+
}
172
+
173
+
public Flux<byte[]> streamNarration(String text) {
1. **Depend on Interfaces**: Always inject `TextToSpeechModel` rather than concrete implementations
327
+
2. **Use Common Options**: Stick to `TextToSpeechOptions` interface methods for maximum portability
328
+
3. **Handle Metadata Gracefully**: Different providers return different metadata; handle it generically
329
+
4. **Test with Multiple Providers**: Ensure your code works with at least two TTS providers
330
+
5. **Document Provider Assumptions**: If you rely on specific provider behavior, document it clearly
331
+
119
332
== Provider-Specific Features
120
333
121
334
While the shared interfaces provide portability, each provider also offers specific features through provider-specific options classes (e.g., `OpenAiAudioSpeechOptions`, `ElevenLabsSpeechOptions`). These classes implement the `TextToSpeechOptions` interface while adding provider-specific capabilities.
0 commit comments