Skip to content

Commit

Permalink
Will combine sentences into paragraphs when exporting txt (#889)
Browse files Browse the repository at this point in the history
  • Loading branch information
raivisdejus committed Aug 17, 2024
1 parent 717f855 commit 6fa9c8d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
13 changes: 10 additions & 3 deletions buzz/transcriber/file_transcriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,16 @@ def write_output(

with open(path, "w", encoding="utf-8") as file:
if output_format == OutputFormat.TXT:
for i, segment in enumerate(segments):
file.write(getattr(segment, segment_key))
file.write("\n")
combined_text = ""
previous_end_time = None

for segment in segments:
if previous_end_time is not None and (segment.start - previous_end_time) >= 2000:
combined_text += "\n\n"
combined_text += getattr(segment, segment_key).strip() + " "
previous_end_time = segment.end

file.write(combined_text)

elif output_format == OutputFormat.VTT:
file.write("WEBVTT\n\n")
Expand Down
14 changes: 11 additions & 3 deletions buzz/widgets/transcription_viewer/transcription_viewer_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,17 @@ def reset_view(self):
segments = self.transcription_service.get_transcription_segments(
transcription_id=self.transcription.id_as_uuid
)
self.text_display_box.setPlainText(
" ".join(segment.text.strip() for segment in segments)
)

combined_text = ""
previous_end_time = None

for segment in segments:
if previous_end_time is not None and (segment.start_time - previous_end_time) >= 2000:
combined_text += "\n\n"
combined_text += segment.text.strip() + " "
previous_end_time = segment.end_time

self.text_display_box.setPlainText(combined_text.strip())
self.text_display_box.show()
self.table_widget.hide()
else: # ViewMode.TRANSLATION
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/usage/translations.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Translations

Default `Translation` task uses Whisper model ability to translate to English. Since version `1.0.0` Buzz supports additional AI translations to any other language.

To use translation feature you will need to configure OpenAI API key and translation settings. Set OpenAI API ket in Preferences. Buzz also supports custom locally running translation AIs that support OpenAI API. For more information on locally running AIs see [ollama](https://ollama.com/blog/openai-compatibility) or [LM Studio](https://lmstudio.ai/).
To use translation feature you will need to configure OpenAI API key and translation settings. Set OpenAI API ket in Preferences. Buzz also supports custom locally running translation AIs that support OpenAI API. For more information on locally running AIs see [ollama](https://ollama.com/blog/openai-compatibility) or [LM Studio](https://lmstudio.ai/). For information on available custom APIs see this [discussion thread](https://github.com/chidiwilliams/buzz/discussions/827)

To configure translation for Live recordings enable it in Advances settings dialog of the Live Recording settings. Enter AI model to use and prompt with instructions for the AI on how to translate. Translation option is also available for files that already have speech recognised. Use Translate button on transcription viewer toolbar.

Expand Down
2 changes: 1 addition & 1 deletion tests/transcriber/transcriber_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_to_timestamp(self):
@pytest.mark.parametrize(
"output_format,output_text",
[
(OutputFormat.TXT, "Bien\nvenue dans\n"),
(OutputFormat.TXT, "Bien venue dans "),
(
OutputFormat.SRT,
"1\n00:00:00,040 --> 00:00:00,299\nBien\n\n2\n00:00:00,299 --> 00:00:00,329\nvenue dans\n\n",
Expand Down
2 changes: 1 addition & 1 deletion tests/widgets/export_transcription_menu_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ def test_should_export_segments(
widget.actions()[0].trigger()

with open(output_file_path, encoding="utf-8") as output_file:
assert "Bien\nvenue dans" in output_file.read()
assert "Bien venue dans" in output_file.read()

0 comments on commit 6fa9c8d

Please sign in to comment.