Live API의 기본 구현을 사용하더라도 사용자를 위한 매력적이고 강력한 상호작용을 빌드할 수 있습니다. 다음 구성 옵션을 사용하여 환경을 더욱 맞춤설정할 수도 있습니다.
응답 음성 및 언어
모델이 특정 음성으로 대답하도록 설정하고 모델이 다른 언어로 대답하도록 영향을 줄 수 있습니다.
대답 음성 지정
|
Gemini API 제공업체를 클릭하여 이 페이지에서 제공업체별 콘텐츠와 코드를 확인합니다. |
Live API는 Chirp 3를 사용하여 HD 음성으로 합성된 음성 응답을 지원합니다.
대답 음성을 지정하지 않으면 기본값은 Puck입니다.
응답 음성을 지정하려면 모델 구성의 일부로 speechConfig 객체 내에서 음성 이름을 설정합니다.
Swift
// ...
let liveModel = FirebaseAI.firebaseAI(backend: .googleAI()).liveModel(
modelName: "gemini-2.5-flash-native-audio-preview-09-2025",
// Configure the model to use a specific voice for its audio response
generationConfig: LiveGenerationConfig(
responseModalities: [.audio],
speech: SpeechConfig(voiceName: "VOICE_NAME")
)
)
// ...
Kotlin
// ...
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).liveModel(
modelName = "gemini-2.5-flash-native-audio-preview-09-2025",
// Configure the model to use a specific voice for its audio response
generationConfig = liveGenerationConfig {
responseModality = ResponseModality.AUDIO
speechConfig = SpeechConfig(voice = Voice("VOICE_NAME"))
}
)
// ...
Java
// ...
LiveGenerativeModel lm = FirebaseAI.getInstance(GenerativeBackend.googleAI()).liveModel(
"gemini-2.5-flash-native-audio-preview-09-2025",
// Configure the model to use a specific voice for its audio response
new LiveGenerationConfig.Builder()
.setResponseModality(ResponseModality.AUDIO)
.setSpeechConfig(new SpeechConfig(new Voice("VOICE_NAME")))
.build()
);
// ...
Web
// ...
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
const liveModel = getLiveGenerativeModel(ai, {
model: "gemini-2.5-flash-native-audio-preview-09-2025",
// Configure the model to use a specific voice for its audio response
generationConfig: {
responseModalities: [ResponseModality.AUDIO],
speechConfig: {
voiceConfig: {
prebuiltVoiceConfig: { voiceName: "VOICE_NAME" },
},
},
},
});
// ...
Dart
// ...
final _liveModel = FirebaseAI.googleAI().liveGenerativeModel(
model: 'gemini-2.5-flash-native-audio-preview-09-2025',
// Configure the model to use a specific voice for its audio response
liveGenerationConfig: LiveGenerationConfig(
responseModalities: [ResponseModalities.audio],
speechConfig: SpeechConfig(voiceName: 'VOICE_NAME'),
),
);
// ...
Unity
// ...
var liveModel = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetLiveModel(
modelName: "gemini-2.5-flash-native-audio-preview-09-2025",
// Configure the model to use a specific voice for its audio response
liveGenerationConfig: new LiveGenerationConfig(
responseModalities: new[] { ResponseModality.Audio },
speechConfig: SpeechConfig.UsePrebuiltVoice("VOICE_NAME")
)
);
// ...
대답 언어에 영향을 미침
Live API 모델은 대답에 적합한 언어를 자동으로 선택합니다.
모델이 영어 이외의 언어로 응답하거나 항상 특정 언어로 응답하도록 하려면 다음 예와 같은 시스템 요청 사항을 사용하여 모델의 응답에 영향을 줄 수 있습니다.
영어 이외의 언어가 적절할 수 있음을 모델에 강조
Listen to the speaker carefully. If you detect a non-English language, respond in the language you hear from the speaker. You must respond unmistakably in the speaker's language.모델이 항상 특정 언어로 응답하도록 지시
RESPOND IN LANGUAGE. YOU MUST RESPOND UNMISTAKABLY IN LANGUAGE.
오디오 입력 및 출력 스크립트
|
Gemini API 제공업체를 클릭하여 이 페이지에서 제공업체별 콘텐츠와 코드를 확인합니다. |
모델의 대답의 일부로 오디오 입력과 모델의 오디오 대답의 스크립트를 받을 수 있습니다. 이 구성은 모델 구성의 일부로 설정합니다.
오디오 입력의 스크립트 작성을 위해
inputAudioTranscription를 추가합니다.모델의 오디오 응답을 텍스트로 변환하려면
outputAudioTranscription를 추가합니다.
다음에 유의하세요.
입력과 출력 모두의 스크립트를 반환하도록 모델을 구성할 수도 있고(다음 예 참고) 둘 중 하나만 반환하도록 구성할 수도 있습니다.
스크립트는 오디오와 함께 스트리밍되므로 각 턴에서 텍스트 부분을 수집하는 것과 같이 스크립트를 수집하는 것이 좋습니다.
스크립트 작성 언어는 오디오 입력과 모델의 오디오 응답에서 추론됩니다.
Swift
// ...
let liveModel = FirebaseAI.firebaseAI(backend: .googleAI()).liveModel(
modelName: "gemini-2.5-flash-native-audio-preview-09-2025",
// Configure the model to return transcriptions of the audio input and output
generationConfig: LiveGenerationConfig(
responseModalities: [.audio],
inputAudioTranscription: AudioTranscriptionConfig(),
outputAudioTranscription: AudioTranscriptionConfig()
)
)
var inputTranscript: String = ""
var outputTranscript: String = ""
do {
let session = try await liveModel.connect()
for try await response in session.responses {
if case let .content(content) = response.payload {
if let inputText = content.inputAudioTranscription?.text {
// Handle transcription text of the audio input
inputTranscript += inputText
}
if let outputText = content.outputAudioTranscription?.text {
// Handle transcription text of the audio output
outputTranscript += outputText
}
if content.isTurnComplete {
// Log the transcripts after the current turn is complete
print("Input audio: \(inputTranscript)")
print("Output audio: \(outputTranscript)")
// Reset the transcripts for the next turn
inputTranscript = ""
outputTranscript = ""
}
}
}
} catch {
// Handle error
}
// ...
Kotlin
// ...
val liveModel = Firebase.ai(backend = GenerativeBackend.googleAI()).liveModel(
modelName = "gemini-2.5-flash-native-audio-preview-09-2025",
// Configure the model to return transcriptions of the audio input and output
generationConfig = liveGenerationConfig {
responseModality = ResponseModality.AUDIO
inputAudioTranscription = AudioTranscriptionConfig()
outputAudioTranscription = AudioTranscriptionConfig()
}
)
val liveSession = liveModel.connect()
fun handleTranscription(input: Transcription?, output: Transcription?) {
input?.text?.let { text ->
// Handle transcription text of the audio input
println("Input Transcription: $text")
}
output?.text?.let { text ->
// Handle transcription text of the audio output
println("Output Transcription: $text")
}
}
liveSession.startAudioConversation(null, ::handleTranscription)
// ...
Java
// ...
ExecutorService executor = Executors.newFixedThreadPool(1);
LiveGenerativeModel lm = FirebaseAI.getInstance(GenerativeBackend.googleAI()).liveModel(
"gemini-2.5-flash-native-audio-preview-09-2025",
// Configure the model to return transcriptions of the audio input and output
new LiveGenerationConfig.Builder()
.setResponseModality(ResponseModality.AUDIO)
.setInputAudioTranscription(new AudioTranscriptionConfig())
.setOutputAudioTranscription(new AudioTranscriptionConfig())
.build()
);
LiveModelFutures liveModel = LiveModelFutures.from(lm);
ListenableFuture sessionFuture = liveModel.connect();
Futures.addCallback(sessionFuture, new FutureCallback() {
@Override
public void onSuccess(LiveSessionFutures ses) {
LiveSessionFutures session = ses;
session.startAudioConversation((Transcription input, Transcription output) -> {
if (input != null) {
// Handle transcription text of the audio input
System.out.println("Input Transcription: " + input.getText());
}
if (output != null) {
// Handle transcription text of the audio output
System.out.println("Output Transcription: " + output.getText());
}
return null;
});
}
@Override
public void onFailure(Throwable t) {
// Handle exceptions
t.printStackTrace();
}
}, executor);
// ...
Web
// ...
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
const liveModel = getLiveGenerativeModel(ai, {
model: 'gemini-2.5-flash-native-audio-preview-09-2025',
// Configure the model to return transcriptions of the audio input and output
generationConfig: {
responseModalities: [ResponseModality.AUDIO],
inputAudioTranscription: {},
outputAudioTranscription: {},
},
});
const liveSession = await liveModel.connect();
liveSession.sendAudioRealtime({ data, mimeType: "audio/pcm" });
const messages = liveSession.receive();
for await (const message of messages) {
switch (message.type) {
case 'serverContent':
if (message.inputTranscription) {
// Handle transcription text of the audio input
console.log(`Input transcription: ${message.inputTranscription.text}`);
}
if (message.outputTranscription) {
// Handle transcription text of the audio output
console.log(`Output transcription: ${message.outputTranscription.text}`);
} else {
// Handle other message types (modelTurn, turnComplete, interruption)
}
default:
// Handle other message types (toolCall, toolCallCancellation)
}
}
// ...
Dart
// ...
final _liveModel = FirebaseAI.googleAI().liveGenerativeModel(
model: 'gemini-2.5-flash-native-audio-preview-09-2025',
// Configure the model to return transcriptions of the audio input and output
liveGenerationConfig: LiveGenerationConfig(
responseModalities: [ResponseModalities.audio],
inputAudioTranscription: AudioTranscriptionConfig(),
outputAudioTranscription: AudioTranscriptionConfig(),
),
);
final LiveSession _session = _liveModel.connect();
await for (final response in _session.receive()) {
LiveServerContent message = response.message;
if (message.inputTranscription?.text case final inputText?) {
// Handle transcription text of the audio input
print('Input: $inputText');
}
if (message.outputTranscription?.text case final outputText?) {
// Handle transcription text of the audio output
print('Output: $outputText');
}
}
// ...
Unity
// ...
var liveModel = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetLiveModel(
modelName: "gemini-2.5-flash-native-audio-preview-09-2025",
// Configure the model to return transcriptions of the audio input and output
liveGenerationConfig: new LiveGenerationConfig(
responseModalities: new[] { ResponseModality.Audio },
inputAudioTranscription: new AudioTranscriptionConfig(),
outputAudioTranscription: new AudioTranscriptionConfig()
)
);
try
{
var session = await liveModel.ConnectAsync();
var stream = session.ReceiveAsync();
await foreach (var response in stream) {
if (response.Message is LiveSessionContent sessionContent) {
if (!string.IsNullOrEmpty(sessionContent.InputTranscription?.Text)) {
// handle transcription text of input audio
}
if (!string.IsNullOrEmpty(sessionContent.OutputTranscription?.Text)) {
// handle transcription text of output audio
}
}
}
}
catch (Exception e)
{
// Handle error
}
// ...
음성 활동 감지(VAD)
이 모델은 연속 오디오 입력 스트림에서 음성 활동 감지(VAD)를 자동으로 실행합니다. VAD는 기본적으로 사용 설정되어 있습니다.
나중에 다시 확인해 주세요.세션 관리
다음 세션 관련 주제에 대해 알아보세요.
다음과 같은 고급 기능
연결 및 세션 길이 제한, 세션 컨텍스트 윈도우 제한, 비율 제한 등 세션 관련 제한
Firebase AI Logic는 세션 관리에 다음 기능을 아직 지원하지 않습니다. 나중에 다시 확인해 주세요.
- 중단 처리
- 세션 길이 연장
- 세션 재개
- 세션과 요청 전반에서 컨텍스트 유지
- 컨텍스트 윈도우 압축