Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First round of fixes for voice experience #349

Merged
merged 4 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion app/javascript/blocks/interfaces/listener_interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,28 @@ export default class extends Interface {
$.attachment = null

$.consideration = words
_startThinking()
}
log_Invoke
async Invoke() { if (!$.processing) {
$.processing = true
Flip.Transcriber.on()
await $.screenService.start()
Flip.Transcriber.on()
Play.Speaker.sound('pop')
}
}
log_Dismiss
Dismiss() { if ($.processing) {
$.processing = false
Flip.Transcriber.on() // so it can wait for "wake" words
Play.Speaker.sound('pip')
}
}

Disable() { $.processing = null
$.screenService.end()
Flip.Transcriber.off()
Play.Speaker.sound('pip')
}

attr_consideration = ''
Expand All @@ -68,4 +72,10 @@ export default class extends Interface {
_referencingTheScreen(words) {
return words.downcase().includeAny(["can you see", "you can see", "do you see", "look at", "this", "my screen", "the screen"])
}

_startThinking() {
Play.Speaker.sound('jeep', () => {
Loop.Speaker.every(4, 'thinking')
})
}
}
2 changes: 2 additions & 0 deletions app/javascript/blocks/interfaces/speaker_interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export default class extends Interface {
log_Prompt
Prompt(words) { $.audioService.sayNext(words) }
Reset() { $.audioService.stop() }
Play(sound, onEnd) { $.audioService.play(sound, onEnd) }
Loop(sec, sound) { $.audioService.playEvery(sec, sound) }

get speaking() { $.audioService.speaking }
get busy() { $.audioService.busy }
Expand Down
3 changes: 3 additions & 0 deletions app/javascript/blocks/interfaces/transcriber_interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export default class extends Interface {
Cover() { $.covered = true }
Uncover() { $.transcriberService.restart()
$.covered = false
Play.Speaker.sound('pop', () => {
Loop.Speaker.every(8, 'typing1')
})
}

attr_words = ''
Expand Down
32 changes: 28 additions & 4 deletions app/javascript/blocks/services/audio_service.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions app/javascript/stimulus/composer_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import viewport from "stimulus/utils/viewport"

export default class extends Controller {
static targets = [ "form", "input", "submit", "overlay", "cancel",
"microphoneEnable", "microphoneDisable", "microphoneShortcut" ]
"microphoneEnable", "microphoneDisable" ]

get cleanInputValue() {
return this.inputTarget.value.trim()
Expand Down Expand Up @@ -42,15 +42,17 @@ export default class extends Controller {
determineSubmitButton() {
if (this.cleanInputValue.length < 1) {
this.submitTarget.classList.add('hidden')
if (this.hasMicrophoneEnableTarget) this.microphoneEnableTarget.classList.remove('hidden') // TODO: remove when enabling feature
if (this.hasCancelTarget) this.cancelTarget.classList.remove('hidden')
} else {
this.submitTarget.classList.remove('hidden')
if (this.hasMicrophoneEnableTarget) this.microphoneEnableTarget.classList.add('hidden') // TODO: remove when enabling feature
if (this.hasCancelTarget) this.cancelTarget.classList.add('hidden')
}
}

toggleMicrophone(event) {
if (!this.hasMicrophoneShortcutTarget) return // TODO: remove when enabling feature
if (!this.hasMicrophoneEnableTarget) return // TODO: remove when enabling feature

event.preventDefault()

Expand All @@ -63,7 +65,7 @@ export default class extends Controller {

boundDetermineMicButton = (event) => { this.determineMicButton(event) }
determineMicButton(event) {
if (!this.hasMicrophoneShortcutTarget) return // TODO: remove when enabling feature
if (!this.hasMicrophoneEnableTarget) return // TODO: remove when enabling feature
if (event?.type == 'turbo:frame-render' && event?.id != 'conversation') return

if (Listener.engaged)
Expand Down Expand Up @@ -147,13 +149,11 @@ export default class extends Controller {

disableComposer() {
this.overlayTarget.classList.remove('hidden')
if (this.hasMicrophoneShortcutTarget) this.microphoneShortcutTarget.classList.add('!hidden') // TODO: fix when enabling feature
this.inputTarget.blur()
}

enableComposer() {
this.overlayTarget.classList.add('hidden')
if (this.hasMicrophoneShortcutTarget) this.microphoneShortcutTarget.classList.remove('!hidden') // TODO: fix when enabling feature
this.focus()
}

Expand Down
51 changes: 28 additions & 23 deletions app/views/messages/_main_column.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,6 @@
|
%>

<% if Feature.enabled?(:voice) %>
<div class="absolute right-20 bottom-6 text-gray-500 hidden md:block" data-composer-target="microphoneShortcut">
Ctrl + M
</div>
<% end %>

<!-- options for the composer right button -->

<% if Feature.enabled?(:voice) %>
Expand Down Expand Up @@ -314,24 +308,35 @@
<!-- the cancel button is z-20, it's declared above the current form and positioned in this same spot -->

<% if Feature.enabled?(:voice) %>
<%= form.button type: "button",
data: {
composer_target: "microphoneEnable",
action: "composer#enableMicrophone"
},
id: "microphone-enable",
class: %w|
<div
id="microphone-enable"
data-composer-target="microphoneEnable"
class="
z-10
absolute right-8 bottom-4
w-[40px] h-[40px]
flex items-center justify-center
text-gray-100 dark:text-gray-600
enabled:text-black
enabled:dark:text-white
| do
%>
<%= icon "microphone", variant: :outline, size: 26, title: 'Voice mode', tooltip: :top %>
<% end %>
absolute
right-8 bottom-4
h-[40px] w-[120px]
flex items-center justify-end
">
<div class="text-gray-500 mr-1 hidden md:block">
Ctrl + M
</div>

<%= form.button type: "button",
data: {
action: "composer#enableMicrophone"
},
class: %w|
flex items-center justify-center
w-[40px] h-[40px]
text-gray-100 dark:text-gray-600
enabled:text-black
enabled:dark:text-white
| do
%>
<%= icon "microphone", variant: :outline, size: 26, title: 'Voice mode', tooltip: :top %>
<% end %>
</div>
<% else %>
<%= form.button type: "button",
disabled: true,
Expand Down
Loading