<commit_before># coding: utf-8
from google.cloud import speech_v1
from google.cloud import storage

from kpi.models.asset import Asset


class AutoTranscription:
    """
    The engine for transcribing audio files
    """
    def store_transcript(self, transcript, asset, submission_id):
        pass


class GoogleTranscribeEngine(AutoTranscription):
    def __init__(self):
        self.destination_path = None
        self.bucket_name = 'kobo-transcription-test'

    def delete_google_file(self):
        """
        Files need to be deleted from google storage after
        the transcript finished to avoid running up the bill
        """
        storage_client = storage.Client()
        bucket = storage_client.bucket(self.bucket_name)
        blob = bucket.blob(self.destination_path)
        blob.delete()

    def get_converted_audio(
            self,
            asset,
            xpath: str,
            submission_id: int,
            user: object
    ):
        attachment = asset.deployment.get_attachment(submission_id, user, xpath=xpath)
        attachment_path = attachment.absolute_flac_path
        filepath = attachment.media_file.name
        return attachment_path, filepath

    def store_file(self, attachment_path: str, filename: str):
        self.destination_path = f"{filename}.flac"

        # send the audio file to google storage<commit_msg>updated google transcribe engine for attachments changes<commit_after># coding: utf-8
from google.cloud import speech_v1
from google.cloud import storage

from kpi.models.asset import Asset


class AutoTranscription:
    """
    The engine for transcribing audio files
    """
    def store_transcript(self, transcript, asset, submission_id):
        pass


class GoogleTranscribeEngine(AutoTranscription):
    def __init__(self):
        self.destination_path = None
        self.bucket_name = 'kobo-transcription-test'

    def delete_google_file(self):
        """
        Files need to be deleted from google storage after
        the transcript finished to avoid running up the bill
        """
        storage_client = storage.Client()
        bucket = storage_client.bucket(self.bucket_name)
        blob = bucket.blob(self.destination_path)
        blob.delete()

    def get_converted_audio(
            self,
            asset,
            xpath: str,
            submission_id: int,
            user: object
    ):
        attachment = asset.deployment.get_attachment(submission_id, user, xpath=xpath)
        attachment_path = attachment.protected_path('flac')
        filepath = attachment.media_file.name
        return attachment_path, filepath

    def store_file(self, attachment_path: str, filename: str):
        self.destination_path = f"{filename}.flac"

        # send the audio file to google storage
{'fraction_non_alphanumeric': 0.07431225437656305, 'fraction_numerical': 0.0014290818149339049, 'mean_word_length': 2.679369250985545, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2013969', 'n_tokens_mistral': 760, 'n_tokens_neox': 734, 'n_words': 205}