feat: add text to speech #69
@@ -0,0 +1,3 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
|
||||||
|
<path d="M10.75 14.75V17.25" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M14.25 7.75V20.25" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M17.75 10.75V17.25" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M21.25 12.75V15.25" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/><path d="M2.75 5.25V3.75H7M11.25 5.25V3.75H7M7 3.75V12.25M7 12.25H5.25M7 12.25H8.75" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 726 B |
@@ -14,8 +14,6 @@ pub enum Command {
|
|||||||
Relays(PublicKey),
|
Relays(PublicKey),
|
||||||
Njump(PublicKey),
|
Njump(PublicKey),
|
||||||
Trace(EventId),
|
Trace(EventId),
|
||||||
Speak(EventId),
|
|
||||||
StopSpeaking,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start or stop dictation in the focused composer
|
// Start or stop dictation in the focused composer
|
||||||
|
|||||||
+11
-25
@@ -937,20 +937,6 @@ impl ChatPanel {
|
|||||||
Command::Trace(id) => {
|
Command::Trace(id) => {
|
||||||
self.open_trace(id, window, cx);
|
self.open_trace(id, window, cx);
|
||||||
}
|
}
|
||||||
Command::Speak(id) => {
|
|
||||||
let text = self.message(id).map(|message| message.preview());
|
|
||||||
|
|
||||||
if let Some(text) = text
|
|
||||||
&& let Err(e) = self.speaker.speak(&text)
|
|
||||||
{
|
|
||||||
window.push_notification(Notification::error(e.to_string()), cx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Command::StopSpeaking => {
|
|
||||||
if let Err(error) = self.speaker.stop() {
|
|
||||||
window.push_notification(Notification::error(error.to_string()), cx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1445,6 +1431,7 @@ impl ChatPanel {
|
|||||||
|
|
||||||
let reply_id = *id;
|
let reply_id = *id;
|
||||||
let dropdown_id = *id;
|
let dropdown_id = *id;
|
||||||
|
let speech_id = *id;
|
||||||
let public_key = *public_key;
|
let public_key = *public_key;
|
||||||
|
|
||||||
let actions = actions.reply(cx.listener(move |this, _event, _window, cx| {
|
let actions = actions.reply(cx.listener(move |this, _event, _window, cx| {
|
||||||
@@ -1460,20 +1447,19 @@ impl ChatPanel {
|
|||||||
actions
|
actions
|
||||||
};
|
};
|
||||||
|
|
||||||
let speaking = self.speaker.speaking();
|
let actions = actions.speech(cx.listener(move |this, _event, window, cx| {
|
||||||
|
let text = this.message(&speech_id).map(|message| message.preview());
|
||||||
|
|
||||||
|
if let Some(text) = text
|
||||||
|
&& let Err(error) = this.speaker.speak(&text)
|
||||||
|
{
|
||||||
|
window.push_notification(Notification::error(error.to_string()), cx);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
actions.dropdown(move |menu, _window, _cx| {
|
actions.dropdown(move |menu, _window, _cx| {
|
||||||
let menu = menu
|
menu.menu("Copy author", Box::new(Command::Copy(public_key)))
|
||||||
.menu("Copy author", Box::new(Command::Copy(public_key)))
|
|
||||||
.menu("Seen on", Box::new(Command::Trace(dropdown_id)))
|
.menu("Seen on", Box::new(Command::Trace(dropdown_id)))
|
||||||
.separator()
|
|
||||||
.menu("Read aloud", Box::new(Command::Speak(dropdown_id)));
|
|
||||||
|
|
||||||
if speaking {
|
|
||||||
menu.menu("Stop speaking", Box::new(Command::StopSpeaking))
|
|
||||||
} else {
|
|
||||||
menu
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -445,8 +445,7 @@ impl GroupPanel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Track the keys rendered by this panel: members, message authors, and
|
/// Track the keys rendered by this panel.
|
||||||
/// activity subjects
|
|
||||||
fn track_participants(&mut self, cx: &mut Context<Self>) {
|
fn track_participants(&mut self, cx: &mut Context<Self>) {
|
||||||
let Some(group) = self.group.upgrade() else {
|
let Some(group) = self.group.upgrade() else {
|
||||||
return;
|
return;
|
||||||
@@ -1060,7 +1059,6 @@ impl GroupPanel {
|
|||||||
panel: cx.weak_entity(),
|
panel: cx.weak_entity(),
|
||||||
admin,
|
admin,
|
||||||
pinned,
|
pinned,
|
||||||
speaking: self.speaker.speaking(),
|
|
||||||
persons: self.directory.clone(),
|
persons: self.directory.clone(),
|
||||||
},
|
},
|
||||||
cx,
|
cx,
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ use person::Directory;
|
|||||||
use settings::AppSettings;
|
use settings::AppSettings;
|
||||||
use state::NostrRegistry;
|
use state::NostrRegistry;
|
||||||
use ui::{
|
use ui::{
|
||||||
Avatar, MessageMedia, MessageRow, REACTION_EMOJIS, ReactionBar, ReplyPreview, group_reactions,
|
Avatar, MessageActions, MessageMedia, MessageRow, REACTION_EMOJIS, ReactionBar, ReplyPreview,
|
||||||
react_menu,
|
group_reactions, react_menu,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::GroupPanel;
|
use crate::GroupPanel;
|
||||||
@@ -27,8 +27,6 @@ pub(crate) struct Actions {
|
|||||||
pub panel: WeakEntity<GroupPanel>,
|
pub panel: WeakEntity<GroupPanel>,
|
||||||
pub admin: bool,
|
pub admin: bool,
|
||||||
pub pinned: bool,
|
pub pinned: bool,
|
||||||
/// Whether the panel's speaker is currently saying something
|
|
||||||
pub speaking: bool,
|
|
||||||
pub persons: Entity<Directory>,
|
pub persons: Entity<Directory>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,9 +88,17 @@ pub(crate) fn render(
|
|||||||
let admin = actions.admin;
|
let admin = actions.admin;
|
||||||
let pinned = actions.pinned;
|
let pinned = actions.pinned;
|
||||||
let group = actions.group;
|
let group = actions.group;
|
||||||
let panel = actions.panel;
|
let speech_panel = actions.panel;
|
||||||
let speaking = actions.speaking;
|
let panel = speech_panel.clone();
|
||||||
let text = message.preview();
|
let speech_text = message.preview();
|
||||||
|
|
||||||
|
let row = row.overlay(MessageActions::new().speech(move |_event, _window, cx| {
|
||||||
|
_ = speech_panel.update_in(cx, |panel, window, cx| {
|
||||||
|
if let Err(error) = panel.speaker.speak(&speech_text) {
|
||||||
|
window.push_notification(Notification::error(error.to_string()), cx);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
let custom = nostr
|
let custom = nostr
|
||||||
.read(cx)
|
.read(cx)
|
||||||
@@ -142,40 +148,6 @@ pub(crate) fn render(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let menu = menu.separator().item({
|
|
||||||
let panel = panel.clone();
|
|
||||||
let text = text.clone();
|
|
||||||
|
|
||||||
PopupMenuItem::new("Read aloud").on_click(move |_event, _window, cx| {
|
|
||||||
if let Err(error) = panel.update_in(cx, |panel, window, cx| {
|
|
||||||
if let Err(error) = panel.speaker.speak(&text) {
|
|
||||||
window.push_notification(Notification::error(error.to_string()), cx);
|
|
||||||
}
|
|
||||||
}) {
|
|
||||||
log::warn!("nip29: reading a message aloud failed: {error}");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
let menu = if speaking {
|
|
||||||
menu.item({
|
|
||||||
let panel = panel.clone();
|
|
||||||
|
|
||||||
PopupMenuItem::new("Stop speaking").on_click(move |_event, _window, cx| {
|
|
||||||
if let Err(error) = panel.update_in(cx, |panel, window, cx| {
|
|
||||||
if let Err(error) = panel.speaker.stop() {
|
|
||||||
window
|
|
||||||
.push_notification(Notification::error(error.to_string()), cx);
|
|
||||||
}
|
|
||||||
}) {
|
|
||||||
log::warn!("nip29: stopping the speaker failed: {error}");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
menu
|
|
||||||
};
|
|
||||||
|
|
||||||
if !admin {
|
if !admin {
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ pub enum IconName {
|
|||||||
PlusChat,
|
PlusChat,
|
||||||
Profile,
|
Profile,
|
||||||
Relay,
|
Relay,
|
||||||
|
Speech,
|
||||||
Search,
|
Search,
|
||||||
Settings,
|
Settings,
|
||||||
Settings2,
|
Settings2,
|
||||||
@@ -58,6 +59,7 @@ impl IconNamed for IconName {
|
|||||||
Self::PlusChat => "icons/plus-chat.svg",
|
Self::PlusChat => "icons/plus-chat.svg",
|
||||||
Self::Profile => "icons/profile.svg",
|
Self::Profile => "icons/profile.svg",
|
||||||
Self::Relay => "icons/relay.svg",
|
Self::Relay => "icons/relay.svg",
|
||||||
|
Self::Speech => "icons/speech.svg",
|
||||||
Self::Search => "icons/search.svg",
|
Self::Search => "icons/search.svg",
|
||||||
Self::Settings => "icons/settings.svg",
|
Self::Settings => "icons/settings.svg",
|
||||||
Self::Settings2 => "icons/settings2.svg",
|
Self::Settings2 => "icons/settings2.svg",
|
||||||
|
|||||||
@@ -597,13 +597,14 @@ pub fn react_menu(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A hovered message's action bar: quick reactions, reply, copy, and an overflow menu.
|
/// A hovered message's action bar: quick reactions, reply, copy, read aloud, and an overflow menu.
|
||||||
#[derive(IntoElement)]
|
#[derive(IntoElement)]
|
||||||
pub struct MessageActions {
|
pub struct MessageActions {
|
||||||
style: StyleRefinement,
|
style: StyleRefinement,
|
||||||
reactions: SmallVec<[(&'static str, SharedClickListener); 4]>,
|
reactions: SmallVec<[(&'static str, SharedClickListener); 4]>,
|
||||||
reply: Option<SharedClickListener>,
|
reply: Option<SharedClickListener>,
|
||||||
copy: Option<(ElementId, SharedString)>,
|
copy: Option<(ElementId, SharedString)>,
|
||||||
|
speech: Option<SharedClickListener>,
|
||||||
dropdown: Option<DropdownBuilder>,
|
dropdown: Option<DropdownBuilder>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -615,6 +616,7 @@ impl MessageActions {
|
|||||||
reactions: SmallVec::new(),
|
reactions: SmallVec::new(),
|
||||||
reply: None,
|
reply: None,
|
||||||
copy: None,
|
copy: None,
|
||||||
|
speech: None,
|
||||||
dropdown: None,
|
dropdown: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -642,6 +644,15 @@ impl MessageActions {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Add the read-aloud button.
|
||||||
|
pub fn speech(
|
||||||
|
mut self,
|
||||||
|
handler: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
|
||||||
|
) -> Self {
|
||||||
|
self.speech = Some(Rc::new(handler));
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Fill the bar's overflow menu.
|
/// Fill the bar's overflow menu.
|
||||||
pub fn dropdown(
|
pub fn dropdown(
|
||||||
mut self,
|
mut self,
|
||||||
@@ -671,10 +682,13 @@ impl RenderOnce for MessageActions {
|
|||||||
reactions,
|
reactions,
|
||||||
reply,
|
reply,
|
||||||
copy,
|
copy,
|
||||||
|
speech,
|
||||||
dropdown,
|
dropdown,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
let has_center = reply.is_some() || copy.is_some();
|
// The leading separator only separates reactions from the center buttons
|
||||||
|
let has_center =
|
||||||
|
!reactions.is_empty() && (reply.is_some() || copy.is_some() || speech.is_some());
|
||||||
|
|
||||||
h_flex()
|
h_flex()
|
||||||
.p_0p5()
|
.p_0p5()
|
||||||
@@ -712,6 +726,16 @@ impl RenderOnce for MessageActions {
|
|||||||
.when_some(copy, |this, (id, value)| {
|
.when_some(copy, |this, (id, value)| {
|
||||||
this.child(Clipboard::new(id).value(value).tooltip("Copy").small())
|
this.child(Clipboard::new(id).value(value).tooltip("Copy").small())
|
||||||
})
|
})
|
||||||
|
.when_some(speech, |this, speech| {
|
||||||
|
this.child(
|
||||||
|
Button::new("speech")
|
||||||
|
.icon(crate::IconName::Speech)
|
||||||
|
.tooltip("Read aloud")
|
||||||
|
.small()
|
||||||
|
.ghost()
|
||||||
|
.on_click(move |event, window, cx| speech(event, window, cx)),
|
||||||
|
)
|
||||||
|
})
|
||||||
.when_some(dropdown, |this, dropdown| {
|
.when_some(dropdown, |this, dropdown| {
|
||||||
this.child(div().flex_shrink_0().h_4().w_px().bg(cx.theme().border))
|
this.child(div().flex_shrink_0().h_4().w_px().bg(cx.theme().border))
|
||||||
.child(
|
.child(
|
||||||
|
|||||||
Reference in New Issue
Block a user