<commit_before>import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';

import { AudioPlayerService } from '../time/audio-player/audio-player.service';
import { ModelImporterService } from '../model/import-export/model-importer.service';
import { TimeService } from '../time/time.service';

@Injectable()
export class FileService {

    private audioFileNameSubject: BehaviorSubject<string>;
    private chartFileNameSubject: BehaviorSubject<string>;

    constructor(
        private audioPlayer: AudioPlayerService,
        private modelImporter: ModelImporterService,
        private timeService: TimeService,
    ) {
        this.audioFileNameSubject = new BehaviorSubject<string>('');
        this.chartFileNameSubject = new BehaviorSubject<string>('');
    }

    get audioFileNames(): Observable<string> {
        return this.audioFileNameSubject.asObservable();
    }

    set audioFile(file: File) {
        if (this.timeService.playing) {
            this.timeService.stop();
        }
        this.audioFileNameSubject.next(file.name);
        const extension = file.name.split('.')[1];
        if (!extension) {
            return;
        }
        this.audioPlayer.setAudio(URL.createObjectURL(file), extension);
    }

    get chartFileNames(): Observable<string> {
        return this.chartFileNameSubject.asObservable();
    }

    set chartFile(file: File) {
        if (this.timeService.playing) {
            this.timeService.stop();
        } else {
            this.timeService.time = 0;
        }
        this.chartFileNameSubject.next(file.name);
        const reader = new FileReader();
        reader.onload = () => {
            this.modelImporter.import(reader.result);
        };
        reader.readAsText(file);
    }
}<commit_msg>feat: Add audio file observable<commit_after>import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable, ReplaySubject } from 'rxjs';

import { AudioPlayerService } from '../time/audio-player/audio-player.service';
import { ModelImporterService } from '../model/import-export/model-importer.service';
import { TimeService } from '../time/time.service';

@Injectable()
export class FileService {

    private audioFileNameSubject: BehaviorSubject<string>;
    private chartFileNameSubject: BehaviorSubject<string>;
    private audioFileSubject: ReplaySubject<Blob>;

    constructor(
        private audioPlayer: AudioPlayerService,
        private modelImporter: ModelImporterService,
        private timeService: TimeService,
    ) {
        this.audioFileNameSubject = new BehaviorSubject<string>('');
        this.chartFileNameSubject = new BehaviorSubject<string>('');
        this.audioFileSubject = new ReplaySubject<Blob>();
    }

    get audioFileNames(): Observable<string> {
        return this.audioFileNameSubject.asObservable();
    }

    set audioFile(file: File) {
        if (this.timeService.playing) {
            this.timeService.stop();
        }
        this.audioFileSubject.next(file);
        this.audioFileNameSubject.next(file.name);
        const extension = file.name.split('.')[1];
        if (!extension) {
            return;
        }
        this.audioPlayer.setAudio(URL.createObjectURL(file), extension);
    }

    get chartFileNames(): Observable<string> {
        return this.chartFileNameSubject.asObservable();
    }

    set chartFile(file: File) {
        if (this.timeService.playing) {
            this.timeService.stop();
        } else {
            this.timeService.time = 0;
        }
        this.chartFileNameSubject.next(file.name);
        const reader = new FileReader();
        reader.onload = () => {
            this.modelImporter.import(reader.result);
        };
        reader.readAsText(file);
    }

    get audioFiles(): Observable<Blob> {
        return this.audioFileSubject.asObservable();
    }
}
{'fraction_non_alphanumeric': 0.11882716049382716, 'fraction_numerical': 0.00102880658436214, 'mean_word_length': 2.801564027370479, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 20, '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': '333753', 'n_tokens_mistral': 1057, 'n_tokens_neox': 1027, 'n_words': 195}