@@ -42,7 +42,7 @@ export const transcription = functions.https.onRequest(async (req, res) => {
42
42
try {
43
43
const transcriptionInDb = await db
44
44
. collection ( "transcriptions" )
45
- . doc ( transcript . id )
45
+ . doc ( id )
46
46
47
47
await transcriptionInDb . set ( {
48
48
id,
@@ -51,42 +51,44 @@ export const transcription = functions.https.onRequest(async (req, res) => {
51
51
audio_url
52
52
} )
53
53
54
- await transcriptionInDb
55
- . collection ( "timestamps" )
56
- . doc ( "utterances" )
57
- . set ( {
58
- utterances : utterances ?. map (
59
- ( { speaker, confidence, start, end, text } ) => ( {
60
- speaker,
61
- confidence,
62
- start,
63
- end,
64
- text
65
- } )
54
+ if ( utterances ) {
55
+ const writer = db . bulkWriter ( )
56
+ for ( let utterance of utterances ) {
57
+ const { speaker, confidence, start, end, text } = utterance
58
+ writer . set (
59
+ db . doc (
60
+ `/transcriptions/${ transcript . id } /utterances/${ utterance . start } `
61
+ ) ,
62
+ { speaker, confidence, start, end, text }
66
63
)
67
- } )
64
+ }
68
65
69
- await transcriptionInDb
70
- . collection ( "timestamps" )
71
- . doc ( "words" )
72
- . set ( {
73
- words
74
- } )
66
+ await writer . close ( )
67
+ }
75
68
76
- const batch = db . batch ( )
69
+ if ( words ) {
70
+ const writer = db . bulkWriter ( )
71
+ for ( let word of words ) {
72
+ writer . set (
73
+ db . doc (
74
+ `/transcriptions/${ transcript . id } /words/${ word . start } `
75
+ ) ,
76
+ word
77
+ )
78
+ }
79
+
80
+ await writer . close ( )
81
+ }
77
82
83
+ const batch = db . batch ( )
78
84
batch . set ( db . collection ( "transcriptions" ) . doc ( transcript . id ) , {
79
85
_timestamp : Timestamp . now ( ) ,
80
86
...transcript
81
87
} )
82
-
83
88
authenticatedEventsInDb . forEach ( doc => {
84
89
batch . update ( doc . ref , { [ "x-maple-webhook" ] : null } )
85
90
} )
86
-
87
91
await batch . commit ( )
88
-
89
- console . log ( "transcript saved in db" )
90
92
} catch ( error ) {
91
93
console . log ( error )
92
94
}
0 commit comments