Skip to content
Draft

Speech #1882

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
6 changes: 5 additions & 1 deletion web/src/lib/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,11 @@
"send": "Zap"
},
"timeline": {
"update": "Show new posts"
"update": "Show new posts",
"options": {
"title": "Options",
"speech": "Speech"
}
},
"emoji": {
"custom": {
Expand Down
6 changes: 5 additions & 1 deletion web/src/lib/i18n/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,11 @@
"send": "Zap"
},
"timeline": {
"update": "新しい投稿を表示"
"update": "新しい投稿を表示",
"options": {
"title": "オプション",
"speech": "読み上げ"
}
},
"emoji": {
"custom": {
Expand Down
12 changes: 10 additions & 2 deletions web/src/lib/timelines/HomeTimeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { filter, share, tap } from 'rxjs';
import type { Event } from 'nostr-typedef';
import { referencesReqEmit, rxNostr, storeSeenOn, tie } from './MainTimeline';
import { WebStorage } from '$lib/WebStorage';
import { persistedStore, WebStorage } from '$lib/WebStorage';
import { kinds as Kind } from 'nostr-tools';
import { get, writable } from 'svelte/store';
import { bookmarkEvent } from '$lib/author/Bookmark';
Expand Down Expand Up @@ -253,7 +253,14 @@ export class HomeTimeline extends NewTimeline {
filterByKind(Kind.ShortTextNote),
tap(({ event }) => userStatusReqEmit([event.pubkey]))
)
.subscribe(({ event }) => saveLastNote(event));
.subscribe(({ event }) => {
saveLastNote(event);

if (get(options).speech) {
const utterance = new SpeechSynthesisUtterance(event.content);
window.speechSynthesis.speak(utterance);
}
});
}

#createForwardFilters(): LazyFilter[] {
Expand Down Expand Up @@ -504,3 +511,4 @@ export class HomeTimeline extends NewTimeline {
}

export const timeline = new HomeTimeline();
export const options = persistedStore('preference:timeline:home:options', { speech: false });
11 changes: 10 additions & 1 deletion web/src/routes/(app)/home/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { onMount } from 'svelte';
import { goto } from '$app/navigation';
import { followees, author } from '$lib/stores/Author';
import { timeline } from '$lib/timelines/HomeTimeline';
import { options, timeline } from '$lib/timelines/HomeTimeline';
import { applyTimelieFilter } from '$lib/TimelineFilter';
import { _ } from 'svelte-i18n';
import { IconAdjustmentsHorizontal } from '@tabler/icons-svelte';
Expand Down Expand Up @@ -42,6 +42,15 @@
<h2>{$_('preferences.timeline_filter.title')}</h2>
<TimelineFilter />
</section>
<section>
<h2>{$_('timeline.options.title')}</h2>
<div>
<label>
<input type="checkbox" bind:checked={$options.speech} />
<span>{$_('timeline.options.speech')}</span>
</label>
</div>
</section>

{#if $author !== undefined}
<section>
Expand Down
Loading