浏览代码

Merge pull request #692 from ollama-webui/tts

feat: convo mode
Timothy Jaeryang Baek 1 年之前
父节点
当前提交
b05fe46bab

+ 1 - 0
src/lib/components/chat/MessageInput.svelte

@@ -674,6 +674,7 @@
 							{#if messages.length == 0 || messages.at(-1).done == true}
 								{#if speechRecognitionEnabled}
 									<button
+										id="voice-input-button"
 										class=" text-gray-600 dark:text-gray-300 transition rounded-lg p-1.5 mr-0.5 self-center"
 										type="button"
 										on:click={() => {

+ 6 - 0
src/lib/components/chat/Messages/ResponseMessage.svelte

@@ -149,6 +149,9 @@
 
 					audio.onended = () => {
 						speaking = null;
+						if ($settings.conversationMode) {
+							document.getElementById('voice-input-button')?.click();
+						}
 					};
 					audio.play().catch((e) => console.error('Error playing audio:', e));
 				}
@@ -166,6 +169,9 @@
 
 						speak.onend = () => {
 							speaking = null;
+							if ($settings.conversationMode) {
+								document.getElementById('voice-input-button')?.click();
+							}
 						};
 						speak.voice = voice;
 						speechSynthesis.speak(speak);

+ 37 - 2
src/lib/components/chat/Settings/Voice.svelte

@@ -6,6 +6,7 @@
 
 	// Voice
 
+	let conversationMode = false;
 	let speechAutoSend = false;
 	let responseAutoPlayback = false;
 
@@ -37,6 +38,21 @@
 		}, 100);
 	};
 
+	const toggleConversationMode = async () => {
+		conversationMode = !conversationMode;
+
+		if (conversationMode) {
+			responseAutoPlayback = true;
+			speechAutoSend = true;
+		}
+
+		saveSettings({
+			conversationMode: conversationMode,
+			responseAutoPlayback: responseAutoPlayback,
+			speechAutoSend: speechAutoSend
+		});
+	};
+
 	const toggleResponseAutoPlayback = async () => {
 		responseAutoPlayback = !responseAutoPlayback;
 		saveSettings({ responseAutoPlayback: responseAutoPlayback });
@@ -50,6 +66,7 @@
 	onMount(async () => {
 		let settings = JSON.parse(localStorage.getItem('settings') ?? '{}');
 
+		conversationMode = settings.conversationMode ?? false;
 		speechAutoSend = settings.speechAutoSend ?? false;
 		responseAutoPlayback = settings.responseAutoPlayback ?? false;
 
@@ -104,7 +121,25 @@
 			</div>
 
 			<div class=" py-0.5 flex w-full justify-between">
-				<div class=" self-center text-xs font-medium">Voice Input Auto-Send</div>
+				<div class=" self-center text-xs font-medium">Conversation Mode</div>
+
+				<button
+					class="p-1 px-3 text-xs flex rounded transition"
+					on:click={() => {
+						toggleConversationMode();
+					}}
+					type="button"
+				>
+					{#if conversationMode === true}
+						<span class="ml-2 self-center">On</span>
+					{:else}
+						<span class="ml-2 self-center">Off</span>
+					{/if}
+				</button>
+			</div>
+
+			<div class=" py-0.5 flex w-full justify-between">
+				<div class=" self-center text-xs font-medium">Auto-send input after 3 sec.</div>
 
 				<button
 					class="p-1 px-3 text-xs flex rounded transition"
@@ -122,7 +157,7 @@
 			</div>
 
 			<div class=" py-0.5 flex w-full justify-between">
-				<div class=" self-center text-xs font-medium">TTS Automatic Playback</div>
+				<div class=" self-center text-xs font-medium">Auto-playback response</div>
 
 				<button
 					class="p-1 px-3 text-xs flex rounded transition"