Spaces:
Sleeping
Sleeping
import assemblyai as aai | |
import pyaudio | |
import wave | |
import requests | |
from configure import auth_key | |
import time | |
import streamlit as st | |
st.title("Transcription de fichier") | |
aai.settings.api_key = f"14ee5668730d41ceb24f2d813caeda4e" | |
# Enregistrement de la voix | |
def voice_rec(): | |
FRAMES_PER_BUFFER = 3200 | |
FORMAT = pyaudio.paInt16 | |
CHANNELS = 1 | |
RATE = 16000 | |
p = pyaudio.PyAudio() | |
stream = p.open( | |
format=FORMAT, | |
channels=CHANNELS, | |
rate=RATE, | |
input=True, | |
frames_per_buffer=FRAMES_PER_BUFFER | |
) | |
filename = st.text_input("Donnez un nom à votre enregistrement", ) | |
filename = filename+".mp3" | |
try: | |
duration = int(st.text_input("Duree de l'enregistrement (en secondes) : ")) | |
except: | |
print("") | |
def rec(): | |
st.markdown("Strat recording...") | |
try: | |
seconds = duration | |
frames = [] | |
for i in range(0, int(RATE/FRAMES_PER_BUFFER*seconds)): | |
data = stream.read(FRAMES_PER_BUFFER) | |
frames.append(data) | |
stream.stop_stream() | |
stream.close() | |
p.terminate() | |
obj = wave.open(filename,"wb") | |
obj.setnchannels(CHANNELS) | |
obj.setsampwidth(p.get_sample_size(FORMAT)) | |
obj.setframerate(RATE) | |
obj.writeframes(b"".join(frames)) | |
obj.close() | |
except: | |
print("") | |
st.button("Lancer l'enregistrement", on_click=rec) | |
try: | |
transcriber = aai.Transcriber() | |
transcript = transcriber.transcribe(filename) | |
transcription = transcript.text | |
st.markdown(transcription) | |
print(transcription) | |
except: | |
print("") | |
return transcription | |
def choose_file_trans(): | |
filename = st.text_input("Entrez le nom du fichier à transcrire: ") | |
filename = filename+".mp3" | |
st.button("Lancer la transcription") | |
try: | |
transcriber = aai.Transcriber() | |
transcript = transcriber.transcribe(filename) | |
transcription = transcript.text | |
st.markdown(transcription) | |
print(transcription) | |
except: | |
print("") | |
return transcription | |
def save_transcript(text): | |
nom = st.text_input("Donnez un nom à la transcription") | |
nom = nom+".txt" | |
if nom is not None: | |
try: | |
with open(nom, "w") as f: | |
f.write(text) | |
f.close() | |
except: | |
print("") | |
#from fpdf import FPDF | |
#def create_doc_pdf(text): | |
# pdf = FPDF() | |
# pdf.add_page() | |
# pdf.set_font("Arial", size=12) | |
#contenu | |
# current_datetime = datetime | |
# pdf.cell(200, 10, txt = transcription, ln = True |