Spaces:
Running
Running
File size: 895 Bytes
9fd131c 17ae025 9fd131c 17ae025 9fd131c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import os
import docx
import streamlit as st
import re
def generate_docx(text: str):
# file_name: str = st.session_state.audio_file_name.replace(".mp3", ".docx")
file_name: str = re.sub(
r'\.(mp3|m4a|ogg|aac)$',
'.docx', st.session_state.audio_file_name,
flags=re.IGNORECASE
)
file_path: str = os.path.join("documents", "docs")
# Ensure the directory exists
os.makedirs(file_path, exist_ok=True)
# full_path: str = os.path.join(file_path, file_name)
if "full_path_docx" not in st.session_state.keys():
st.session_state.full_path_docx = os.path.join(file_path, file_name)
# Crea un nuevo documento
doc = docx.Document()
# Agrega un párrafo al documento
doc.add_paragraph(f"Texto del audio transcrito:\n\n{text}")
# Guarda el documento en un archivo .docx
doc.save(st.session_state.full_path_docx)
|