-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrs2txt.sh
executable file
·55 lines (43 loc) · 1.37 KB
/
trs2txt.sh
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
#!/bin/bash
# Check if input argument is provided
if [ -z "$1" ]; then
echo "Usage: $0 <directory_or_file_list.txt>"
exit 1
fi
# Input is a directory
if [ -d "$1" ]; then
DIRECTORY=$1
# Loop through all .trs files in the directory
for file in "$DIRECTORY"/*.trs; do
# Check if any .trs files exist
if [ ! -e "$file" ]; then
echo "No .trs files found in the directory."
exit 1
fi
# Extract the base name of the file (without extension)
base_name=$(basename "$file" .trs)
# Convert .trs file to .txt using transcriber
transcriber -export text "$file" > "$DIRECTORY/$base_name.txt"
echo "Converted $file to $base_name.txt"
done
# Input is a .txt file containing a list of .trs filenames
elif [ -f "$1" ] && [[ "$1" == *.txt ]]; then
FILE_LIST=$1
# Loop through each line in the file list
while IFS= read -r file; do
# Check if the .trs file exists
if [ ! -f "$file" ]; then
echo "File not found: $file"
continue
fi
# Extract the base name of the file (without extension)
base_name=$(basename "$file" .trs)
dir_name=$(dirname "$file")
# Convert .trs file to .txt using transcriber
transcriber -export text "$file" > "$dir_name/$base_name.txt"
echo "Converted $file to $base_name.txt"
done < "$FILE_LIST"
else
echo "Error: $1 is not a valid directory or .txt file."
exit 1
fi