Investigamos en distintos sitios para traerte la respuesta para tu inquietud, en caso de alguna inquietud déjanos la duda y respondemos porque estamos para ayudarte.
Ejemplo: código Python de voz a texto
# importing libraries import speech_recognition as sr
import os
from pydub import AudioSegment
from pydub.silence import split_on_silence
# create a speech recognition object
r = sr.Recognizer()# a function that splits the audio file into chunks# and applies speech recognitiondefget_large_audio_transcription(path):"""
Splitting the large audio file into chunks
and apply speech recognition on each of these chunks
"""# open the audio file using pydub
sound = AudioSegment.from_wav(path)# split audio sound where silence is 700 miliseconds or more and get chunks
chunks = split_on_silence(sound,# experiment with this value for your target audio file
min_silence_len =500,# adjust this per requirement
silence_thresh = sound.dBFS-14,# keep the silence for 1 second, adjustable as well
keep_silence=500,)
folder_name ="audio-chunks"# create a directory to store the audio chunksifnot os.path.isdir(folder_name):
os.mkdir(folder_name)
whole_text =""# process each chunk for i, audio_chunk inenumerate(chunks, start=1):# export audio chunk and save it in# the `folder_name` directory.
chunk_filename = os.path.join(folder_name,f"chunki.wav")
audio_chunk.export(chunk_filename,format="wav")# recognize the chunkwith sr.AudioFile(chunk_filename)as source:
audio_listened = r.record(source)# try converting it to texttry:
text = r.recognize_google(audio_listened)except sr.UnknownValueError as e:print("Error:",str(e))else:
text =f"text.capitalize(). "print(chunk_filename,":", text)
whole_text += text
# return the text for all chunks detectedreturn whole_text
Reseñas y puntuaciones del artículo
Te invitamos a añadir valor a nuestro contenido informacional tributando tu veteranía en las interpretaciones.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)