Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2021-060
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2021-060
2021-060
Commits
c5ceca8e
Commit
c5ceca8e
authored
Jul 04, 2021
by
chalikaM
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
convert speech to voice
parent
0e9d90dd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
0 deletions
+56
-0
speechToText.py
speechToText.py
+56
-0
No files found.
speechToText.py
0 → 100644
View file @
c5ceca8e
# 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 recognition
def
get_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 chunks
if
not
os
.
path
.
isdir
(
folder_name
):
os
.
mkdir
(
folder_name
)
whole_text
=
""
# process each chunk
for
i
,
audio_chunk
in
enumerate
(
chunks
,
start
=
1
):
# export audio chunk and save it in
# the `folder_name` directory.
chunk_filename
=
os
.
path
.
join
(
folder_name
,
f
"chunk{i}.wav"
)
audio_chunk
.
export
(
chunk_filename
,
format
=
"wav"
)
# recognize the chunk
with
sr
.
AudioFile
(
chunk_filename
)
as
source
:
audio_listened
=
r
.
record
(
source
)
# try converting it to text
try
:
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 detected
print
(
whole_text
)
return
whole_text
path
=
"videoplayback_1_.wav"
print
(
"
\n
Full text:"
,
get_large_audio_transcription
(
path
))
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment