Scripting Audio Conversations (part 2) - User Files Upload with Google SpeechToText and Python Dash

Опубликовано: 10 Октябрь 2024
на канале: Andrew Fung
740
26

Hello Everyone! My name is Andrew Fung, in this video, I will be showing you how you can upload an audio conversation file and get the transcription of using Google’s Speech-To-Text API and display the script on the web using Python Dash. In this second part of the video, we will be focusing on allowing users to input multiple audio files and displaying the transcription results on the website.

#speechtotext #googlecloud #speakerdiarization #python #dash
#speakerdetection

Installation and Setup!
Google Speech to Text:
https://cloud.google.com/support-hub
https://cloud.google.com/speech-to-te...

Dash documentation: https://dash.plotly.com/dash-core-com...

Source code for this project:
https://github.com/Andrew-FungKinHo/Y...

Check out my Github!
https://github.com/Andrew-FungKinHo

How I make my YouTube videos:
⌨️ Keyboard - Nuphy Air75 Mechanical Keyboard - https://amzn.to/3Xu4PD3
🎙 Microphone - MAONO A04 Professional Podcaster USB Microphone - https://amzn.to/3k8ocD5
🖱 Mouse - Microsoft Bluetooth Ergonomic Mouse - https://amzn.to/3CHhdHJ
🔌 Accessories - Laptop Docking Station for MacBook Pro - https://amzn.to/3CHi5Mv

Timestamps
0:00​ | Intro
1:18 | Get transcript function
2:47 | Dash app script
15:10 | Out tro

Full code:
———————————————————————————————
from speaker import get_transcript
import datetime

import dash
from dash.dependencies import Input, Output, State
import dash_core_components as dcc
import dash_html_components as html

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwg...]

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
intial layout
app.layout = html.Div([
dcc.Upload(
id='upload-image',
children=html.Div([
'Drag and Drop or ',
html.A('Select Files')
]),
style={
'width': '100%',
'height': '60px',
'lineHeight': '60px',
'borderWidth': '1px',
'borderStyle': 'dashed',
'borderRadius': '5px',
'textAlign': 'center',
'margin': '10px'
},
Allow multiple files to be uploaded
multiple=True
),
html.Div(id='output-image-upload'),
])

layout after an upload is detected
def parse_contents(contents, filename, date):
if contents is not None:
content_type, content_string = contents.split(',')

script = get_transcript(filename,content_type)

return html.Div([
html.H5(filename),
html.H6(datetime.datetime.fromtimestamp(date)),
html.Audio(id="player",src=contents,controls=True,style={"width": "50%"}),
html.Hr(),
html.Div('Transcript'),
html.Plaintext(script),
])


@app.callback(Output('output-image-upload', 'children'),
Input('upload-image', 'contents'),
State('upload-image', 'filename'),
State('upload-image', 'last_modified'))
def update_output(list_of_contents, list_of_names, list_of_dates):
if list_of_contents is not None:
children = [
parse_contents(c, n, d) for c, n, d in
zip(list_of_contents, list_of_names, list_of_dates)]
return children


if _name_ == '__main__':
app.run_server(debug=True)

———————————————————————————————

Feel free to drop a like and comment if you enjoy and video and let me know if you want me to do other types of programming videos ;) !!!