-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstep 1.py
135 lines (95 loc) · 2.96 KB
/
step 1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#%%
import pandas as pd
import numpy as py
#%%
transcripts = pd.read_csv("transcript_metadata.csv",encoding = "ISO-8859-1")
audios = pd.read_csv("audio_metadata.csv")
transcripts_final = transcripts
#%%
transcripts.head()
#%%
audios.head()
#%%
audios.Ticker
#%%
audio_ticker_list = set(audios.Ticker)
len(audio_ticker_list)
#%%
# audios_test = audios.loc[(audios.Ticker == "CBB")]
audios_test = audios.loc[(audios.Ticker == "CBB") & (audios.Year == "2018")]
audios_test
#%%
# transcript_test = transcripts.loc[(transcripts.Symbol == "CBB")]
transcript_test = transcripts.loc[(transcripts.Symbol == "CBB") & (transcripts.Year == 2018)]
transcript_test
#%%
transcripts["Quarter"] = pd.to_datetime(transcripts.TextDateTime).dt.quarter
#%%
audios["Quarter"].head()
#%%
transcripts["Quarter"]=transcripts["Quarter"].fillna(0)
transcripts["Quarter"] = transcripts["Quarter"].astype(int)
#%%
date_list = []
count =0
for date in transcripts.TextDateTime:
try:
temp = date[5:7]+ "/" + date[8:10] + "/" + date[0:4]
except BaseException:
date_list.append(0)
else:
date_list.append(temp)
#%%
filename_list = []
for transcript in transcripts.itertuples(index=True, name='Pandas'):
flag = False
for audio in audios.itertuples(index=True, name='Pandas'):
if (transcript[3]==audio[1]) and (transcript[7]==audio[3]) and (transcript[15]==audio[2][1]) and (transcript[16]==audio[7]) and (transcript[1]==audio[4]):
filename_list.append(audio[11])
flag = True
break
if(not flag):
filename_list.append("NaN")
#%%
transcripts_final["the corresponding audio file name"] = pd.DataFrame(filename_list)
#%% [markdown]
# audio conversion
#%% [markdown]
# install ffmpeg, pydub before using
#%% [markdown]
# m4a -> mp3 increase file size a HELL LOT, be aware when using
#%%
from pydub import AudioSegment
import os
#%% [markdown]
# config the input output folders manually
#%%
path = os.getcwd()
audio_input_folder = "sample"
audio_output_folder = "audio_output"
#%% [markdown]
# single file conversion
#%%
sound = AudioSegment.from_file(path +"/" audio_input_folder + "/" + "1Q_2013_Pike_Electric_Corporation_Earnings_Conference_Call.m4a")
sound.export(path + "/" + audio_output_folder + "/" + "test.mp3", format="mp3", bitrate="128k")
#%% [markdown]
# batch conversion
#%% [markdown]
# BE AWARE OF THE LAGGGGGGGG
#%%
filelist = os.listdir(path + "/" + audio_input_folder)
#%% [markdown]
# file checking
#%%
for file in filelist:
if len(file) <= 5:
filelist.remove(file)
print(file + " is wrong")
elif file[-4:] != ".m4a":
filelist.remove(file)
print(file + " is wrong")
#%%
for file in filelist:
sound = AudioSegment.from_file(path + "/" + audio_input_folder + "/" + file)
mp3name = file[:-4] + ".mp3"
sound.export(path + "/" + audio_output_folder + "/" + mp3name, format="mp3", bitrate="128k")