Skip to content
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ version may change things that need attention when updating, and these notes say
FLAC. Visitors hear a copy in the item page's own player, which can jump about. Names, places, dates, cover pictures
and everything else the file carries in tags are cut out of that copy; the sound itself is not re-encoded. The original
stays with curators. A file whose structure the archive cannot follow is refused rather than served. OGG/Opus is not
accepted yet. Recordings are not yet searched or transcribed.
accepted yet. An item with a recording is published only when its description holds the transcript or "Still needs a transcription" is ticked; the handbook shows how to make one on your own computer with whisper.cpp.

### For people running an archive

Expand Down
11 changes: 9 additions & 2 deletions docs/curator-handbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,15 @@ sound itself is exactly the original's. The original stays with curators ("Origi
sense of a file, it says "No preview could be created" and offers nothing to visitors: try saving it again from the recorder
or converting it to MP3 or WAV. OGG and Opus are not accepted yet.

A recording cannot be searched. Write down in the description what is said, or at least who and where, and tick "Still needs a
transcription" until there is a transcript.
Sound cannot be searched, and not everyone can listen. So an item with a recording is published only when its description holds
the transcript, or when "Still needs a transcription" is ticked. Visitors then read the description beside the player, and
search finds the words in it.

**Making a transcript on your own computer.** Nothing is sent anywhere. Install [whisper.cpp](https://github.com/ggml-org/whisper.cpp),
download one of its models (the "small" model is a good start) and run, for example,
`whisper-cli -m ggml-small.bin -l de -f interview.wav -otxt`. It needs a WAV file at 16 kHz; `ffmpeg -i interview.mp3 -ar 16000
-ac 1 interview.wav` makes one. Read the result through while listening: names and dialect words are often wrong. Paste it into the
description and untick the box once it is checked.

## Rights, credit and what only you see

Expand Down
11 changes: 9 additions & 2 deletions docs/handbuch-kuratoren.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,15 @@ ist genau der des Originals. Das Original bleibt bei den Kuratoren („Original
anfangen, steht dort „Es konnte keine Vorschau erstellt werden“, und Besucher bekommen nichts: speichern Sie sie noch einmal aus dem
Aufnahmegerät oder wandeln Sie sie in MP3 oder WAV um. OGG und Opus werden noch nicht angenommen.

Eine Aufnahme lässt sich nicht durchsuchen. Schreiben Sie in die Beschreibung, was gesagt wird, oder wenigstens wer und wo, und setzen Sie
den Haken bei „Muss noch abgeschrieben werden“, bis es eine Abschrift gibt.
Ton lässt sich nicht durchsuchen, und nicht jeder kann zuhören. Darum wird ein Eintrag mit einer Aufnahme nur veröffentlicht, wenn die
Beschreibung die Abschrift enthält oder „Muss noch abgeschrieben werden“ angehakt ist. Besucher lesen die Beschreibung neben dem Player,
und die Suche findet die Wörter darin.

**Eine Abschrift auf dem eigenen Computer erstellen.** Nichts wird irgendwohin gesendet. Installieren Sie
[whisper.cpp](https://github.com/ggml-org/whisper.cpp), laden Sie eines seiner Modelle herunter (das Modell „small“ ist ein guter Anfang) und
starten Sie zum Beispiel `whisper-cli -m ggml-small.bin -l de -f gespraech.wav -otxt`. Es braucht eine WAV-Datei mit 16 kHz;
`ffmpeg -i gespraech.mp3 -ar 16000 -ac 1 gespraech.wav` erzeugt eine. Lesen Sie das Ergebnis beim Zuhören durch: Namen und Mundartwörter
sind oft falsch. Fügen Sie es in die Beschreibung ein und nehmen Sie den Haken heraus, sobald es geprüft ist.

## Rechte, Nennung und was nur Sie sehen

Expand Down
2 changes: 1 addition & 1 deletion docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ shows the years of its published items. M19 is complete.
of its own and is not worth holding the rest up.
*Built:* a recording is a `MediaFile` with an `audio/*` type and no picture sizes, so every query that picks a cover skips
it; its stripped copy is `audio/{StorageId}`. No new column, so no migration and no change to the export.
- **Part 2: the transcript.** An item with audio needs a transcript before it is published, or the "transcript to follow"
- **Part 2: the transcript** (built: the description is the transcript, shown beside the player and searched like any text). An item with audio needs a transcript before it is published, or the "transcript to follow"
flag (the existing "needs transcription" flag). The transcript is searched and shown beside the player. The handbook
documents a local whisper.cpp workflow, as "Not planned" promises.

Expand Down
4 changes: 4 additions & 0 deletions src/Commonage.Web/Pages/Admin/Items/Bulk.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
{
<p class="alert alert-warning">@T["Left out, because they have no title yet: {0}.", Model.WithoutTitle]</p>
}
@if (Model.NoTranscript > 0)
{
<p class="alert alert-warning">@T["Left out, because a recording has no transcript yet: {0}.", Model.NoTranscript]</p>
}
@if (Model.NotDrafts > 0)
{
<p class="alert alert-info">@T["Left out, because they are not drafts: {0}. A contribution needs a decision of its own, on its own page.", Model.NotDrafts]</p>
Expand Down
15 changes: 13 additions & 2 deletions src/Commonage.Web/Pages/Admin/Items/Bulk.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public string? Back

public int WithoutTitle { get; private set; }
public int NotDrafts { get; private set; }
public int NoTranscript { get; private set; }

/// <summary>Items that already hold a date or a statement, which would be replaced.</summary>
public int WouldBeReplaced { get; private set; }
Expand Down Expand Up @@ -150,6 +151,9 @@ public async Task<IActionResult> OnPostApplyAsync(CancellationToken cancellation
.Where(i => ids.Contains(i.Id))
.OrderBy(i => i.Id)
.ToListAsync(cancellationToken);
// A recording nobody can read needs its transcript first, as on the item's own page.
if (Action == BulkAction.Publish)
withoutTranscript = await WithoutTranscript(db.ArchiveItems.Where(i => ids.Contains(i.Id))).Select(i => i.Id).ToHashSetAsync(cancellationToken);
var tags = Action == BulkAction.AddTags ? await db.FindOrCreateTagsAsync(tagNames, cancellationToken) : [];

var now = DateTime.UtcNow;
Expand Down Expand Up @@ -215,7 +219,13 @@ private bool Apply(ArchiveItem item, List<Tag> tags, DateTime now)
}
}

private static bool IsPublishable(ArchiveItem item) => item.Status == ItemStatus.Draft && item.CanBePublished;
private HashSet<int> withoutTranscript = [];

private bool IsPublishable(ArchiveItem item) => item.Status == ItemStatus.Draft && item.CanBePublished && !withoutTranscript.Contains(item.Id);

private static IQueryable<ArchiveItem> WithoutTranscript(IQueryable<ArchiveItem> items) =>
items.Where(i => i.Status == ItemStatus.Draft && (i.Description == null || i.Description.Trim() == "") && !i.NeedsTranscription
&& i.MediaFiles.Any(f => f.ContentType.StartsWith("audio/")));

private List<int> ParseIds() =>
Ids.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(id => int.TryParse(id, out var number) ? number : 0).Where(id => id > 0).ToList();
Expand All @@ -226,7 +236,8 @@ private async Task ShowAsync(List<int> ids, CancellationToken cancellationToken)
Count = await items.CountAsync(cancellationToken);
WithoutTitle = await items.CountAsync(i => i.Status == ItemStatus.Draft && i.Title == "", cancellationToken);
NotDrafts = await items.CountAsync(i => i.Status != ItemStatus.Draft, cancellationToken);
WillChange = Action == BulkAction.Publish ? Count - WithoutTitle - NotDrafts : Count;
NoTranscript = Action == BulkAction.Publish ? await WithoutTranscript(items).CountAsync(i => i.Title != "", cancellationToken) : 0;
WillChange = Action == BulkAction.Publish ? Count - WithoutTitle - NotDrafts - NoTranscript : Count;
WouldBeReplaced = Action switch
{
BulkAction.SetDate => await items.CountAsync(i => i.DateText != null, cancellationToken),
Expand Down
6 changes: 6 additions & 0 deletions src/Commonage.Web/Pages/Admin/Items/Edit.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ public async Task<IActionResult> OnPostAsync(int? id, string? command, string? t
}
}

// A recording nobody can read is not found by search and is closed to anyone who cannot listen: it needs a
// transcript in the description, or the promise of one.
if (command == "publish" && id is not null && string.IsNullOrWhiteSpace(Input.Description) && !Input.NeedsTranscription
&& await db.MediaFiles.AnyAsync(f => f.ArchiveItemId == id && f.ContentType.StartsWith("audio/")))
ModelState.AddModelError("Input.Description", localizer["A recording needs its transcript in the description before it is published, or tick that a transcript will follow."]);

if (!ModelState.IsValid)
{
// A browser cannot fill in chosen files again when a form comes back, so it has to be said.
Expand Down
2 changes: 2 additions & 0 deletions src/Commonage.Web/Resources/SharedResource.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -995,4 +995,6 @@
<data name="Recording of {0}" xml:space="preserve"><value>Aufnahme: {0}</value></data>
<data name="Preparing the recording…" xml:space="preserve"><value>Aufnahme wird vorbereitet…</value></data>
<data name="Recording {0} of {1}" xml:space="preserve"><value>Aufnahme {0} von {1}</value></data>
<data name="A recording needs its transcript in the description before it is published, or tick that a transcript will follow." xml:space="preserve"><value>Eine Aufnahme braucht vor der Veröffentlichung ihre Abschrift in der Beschreibung, oder setzen Sie den Haken, dass eine Abschrift folgt.</value></data>
<data name="Left out, because a recording has no transcript yet: {0}." xml:space="preserve"><value>Ausgelassen, weil eine Aufnahme noch keine Abschrift hat: {0}.</value></data>
</root>
2 changes: 2 additions & 0 deletions src/Commonage.Web/Resources/SharedResource.resx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<data name="A new name changes the tag on every item that has it, also in the search." xml:space="preserve"><value>A new name changes the tag on every item that has it, also in the search.</value></data>
<data name="A new setup link lets the person choose a new password, for example when they forgot theirs. Earlier links stop working. A disabled account cannot log in, but its history stays in the activity log." xml:space="preserve"><value>A new setup link lets the person choose a new password, for example when they forgot theirs. Earlier links stop working. A disabled account cannot log in, but its history stays in the activity log.</value></data>
<data name="A photo description can be at most {0, plural, one {# character} other {# characters}} long." xml:space="preserve"><value>A photo description can be at most {0, plural, one {# character} other {# characters}} long.</value><comment>Has a count. Write a form for each one your language needs, in ICU MessageFormat.</comment></data>
<data name="A recording needs its transcript in the description before it is published, or tick that a transcript will follow." xml:space="preserve"><value>A recording needs its transcript in the description before it is published, or tick that a transcript will follow.</value></data>
<data name="A rights statement" xml:space="preserve"><value>A rights statement</value></data>
<data name="A tag can be at most {0, plural, one {# character} other {# characters}} long." xml:space="preserve"><value>A tag can be at most {0, plural, one {# character} other {# characters}} long.</value><comment>Has a count. Write a form for each one your language needs, in ICU MessageFormat.</comment></data>
<data name="A tag can be at most {1} characters long." xml:space="preserve"><value>A tag can be at most {1} characters long.</value></data>
Expand Down Expand Up @@ -349,6 +350,7 @@
<data name="Later" xml:space="preserve"><value>Later</value></data>
<data name="Later: {0}" xml:space="preserve"><value>Later: {0}</value></data>
<data name="Leave this field empty" xml:space="preserve"><value>Leave this field empty</value></data>
<data name="Left out, because a recording has no transcript yet: {0}." xml:space="preserve"><value>Left out, because a recording has no transcript yet: {0}.</value></data>
<data name="Left out, because the archive already has them: {0}" xml:space="preserve"><value>Left out, because the archive already has them: {0}</value></data>
<data name="Left out, because they are not drafts: {0}. A contribution needs a decision of its own, on its own page." xml:space="preserve"><value>Left out, because they are not drafts: {0}. A contribution needs a decision of its own, on its own page.</value></data>
<data name="Left out, because they have no title yet: {0}." xml:space="preserve"><value>Left out, because they have no title yet: {0}.</value></data>
Expand Down
81 changes: 81 additions & 0 deletions tests/Commonage.Tests/AudioTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;
using Commonage.Web.Domain;
using Commonage.Web.Media;
using Commonage.Web.Pages.Admin.Items;
using Microsoft.EntityFrameworkCore;

namespace Commonage.Tests;
Expand Down Expand Up @@ -234,6 +235,86 @@ await app.WithDbAsync(async db =>
Assert.Equal(HttpStatusCode.NotFound, (await visitor.GetAsync($"/media/{file.Id}/audio")).StatusCode);
}

[Fact]
public async Task A_recording_is_published_only_with_a_transcript_or_the_promise_of_one()
{
using var curator = app.CreateClient();
await Browser.LogInAsCuratorAsync(curator);
var (itemId, _) = await UploadAsync(curator, "interview.mp3", RecordingWithTags());
await app.WithDbAsync(async db => { (await db.ArchiveItems.SingleAsync(i => i.Id == itemId)).Status = ItemStatus.Draft; return await db.SaveChangesAsync(); });
var item = await app.WithDbAsync(db => db.ArchiveItems.AsNoTracking().SingleAsync(i => i.Id == itemId));

async Task<HttpResponseMessage> PublishAsync(string description, bool transcriptToFollow)
{
var fields = new Dictionary<string, string>
{
["Input.Title"] = item.Title, ["Input.CollectionId"] = item.CollectionId.ToString(),
["Input.Description"] = description, ["command"] = "publish",
};
if (transcriptToFollow)
fields["Input.NeedsTranscription"] = "true";
return await Browser.SendFormAsync(curator, $"/Admin/Items/Edit/{itemId}", fields);
}

async Task<ItemStatus> StatusAsync() => (await app.WithDbAsync(db => db.ArchiveItems.AsNoTracking().SingleAsync(i => i.Id == itemId))).Status;

await PublishAsync(" ", false);
Assert.Equal(ItemStatus.Draft, await StatusAsync());

await PublishAsync("", true);
Assert.Equal(ItemStatus.Published, await StatusAsync());
}

[Fact]
public async Task Publishing_many_leaves_out_a_recording_that_has_no_transcript()
{
using var curator = app.CreateClient();
await Browser.LogInAsCuratorAsync(curator);
var (bare, _) = await UploadAsync(curator, "one.mp3", RecordingWithTags());
var (promised, _) = await UploadAsync(curator, "two.mp3", RecordingWithTags());
await app.WithDbAsync(async db =>
{
foreach (var item in await db.ArchiveItems.Where(i => i.Id == bare || i.Id == promised).ToListAsync())
{
item.Status = ItemStatus.Draft;
item.Description = null;
item.NeedsTranscription = item.Id == promised;
}
return await db.SaveChangesAsync();
});

var page = await curator.GetStringAsync("/Admin");
var response = await curator.PostAsync("/Admin/Items/Bulk?handler=Apply", new FormUrlEncodedContent(new Dictionary<string, string>
{
["__RequestVerificationToken"] = Browser.Token(page), ["Action"] = nameof(BulkAction.Publish), ["Ids"] = $"{bare},{promised}",
}));
response.EnsureSuccessStatusCode();

var after = await app.WithDbAsync(db => db.ArchiveItems.AsNoTracking().Where(i => i.Id == bare || i.Id == promised).ToDictionaryAsync(i => i.Id, i => i.Status));
Assert.Equal(ItemStatus.Draft, after[bare]);
Assert.Equal(ItemStatus.Published, after[promised]);
}

[Fact]
public async Task A_recording_with_a_transcript_in_the_description_is_published_and_found_by_its_words()
{
using var curator = app.CreateClient();
await Browser.LogInAsCuratorAsync(curator);
var (itemId, _) = await UploadAsync(curator, "interview.mp3", RecordingWithTags());
await app.WithDbAsync(async db => { (await db.ArchiveItems.SingleAsync(i => i.Id == itemId)).Status = ItemStatus.Draft; return await db.SaveChangesAsync(); });
var item = await app.WithDbAsync(db => db.ArchiveItems.AsNoTracking().SingleAsync(i => i.Id == itemId));
var word = $"smithy{Guid.NewGuid():N}";

await Browser.SendFormAsync(curator, $"/Admin/Items/Edit/{itemId}", new()
{
["Input.Title"] = item.Title, ["Input.CollectionId"] = item.CollectionId.ToString(),
["Input.Description"] = $"We walked past the {word} every morning.", ["command"] = "publish",
});

using var visitor = app.CreateClient();
Assert.Contains($"/items/{itemId}", await visitor.GetStringAsync($"/search?q={word}"));
}

[Fact]
public async Task A_recording_that_is_not_built_as_it_says_fails_without_a_copy_for_anyone()
{
Expand Down
Loading