Mongar28
Correccion de error en la extensi贸n del archvio docx
17ae025
raw
history blame contribute delete
No virus
895 Bytes
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)