Skip to content

Commit

Permalink
remove creating an output directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Epic-Eric committed Aug 5, 2024
1 parent a385388 commit dfc5490
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
75 changes: 75 additions & 0 deletions simuleval/test/test_visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import tempfile
from pathlib import Path
import simuleval.cli as cli
import shutil
import json

ROOT_PATH = Path(__file__).parents[2]

Expand Down Expand Up @@ -47,11 +49,83 @@ def test_visualize(root_path=ROOT_PATH):
source_length = len(f.readlines())
images = list(Path(visual_folder_path).glob("*.png"))
assert len(images) == source_length
shutil.rmtree("output")


def test_visualize_score_only(root_path=ROOT_PATH):
args_path = Path.joinpath(root_path, "examples", "speech_to_text")
os.chdir(args_path)

# Create sample instances.log and config.yaml in output directory
Path.mkdir("output")
os.chdir("output")
with open("config.yaml", "w") as config:
config.write("source_type: speech\n")
config.write("target_type: speech")
with open("instances.log", "w") as instances:
json.dump(
{
"index": 0,
"prediction": "This is a synthesized audio file to test your simultaneous speech, to speak to speech, to speak translation system.",
"delays": [
1500.0,
2000.0,
2500.0,
3000.0,
3500.0,
4000.0,
4500.0,
5000.0,
5500.0,
6000.0,
6500.0,
6849.886621315192,
6849.886621315192,
6849.886621315192,
6849.886621315192,
6849.886621315192,
6849.886621315192,
6849.886621315192,
6849.886621315192,
],
"elapsed": [
1947.3278522491455,
2592.338800430298,
3256.8109035491943,
3900.0539779663086,
4561.986684799194,
5216.205835342407,
5874.6888637542725,
6526.906728744507,
7193.655729293823,
7852.792739868164,
8539.628744125366,
9043.279374916267,
9043.279374916267,
9043.279374916267,
9043.279374916267,
9043.279374916267,
9043.279374916267,
9043.279374916267,
9043.279374916267,
],
"prediction_length": 19,
"reference": "This is a synthesized audio file to test your simultaneous speech to text and to speech to speach translation system.",
"source": [
"test.wav",
"samplerate: 22050 Hz",
"channels: 1",
"duration: 6.850 s",
"format: WAV (Microsoft) [WAV]",
"subtype: Signed 16 bit PCM [PCM_16]",
],
"source_length": 6849.886621315192,
},
instances,
)

os.chdir(args_path)

with tempfile.TemporaryDirectory() as tmpdirname:
cli.sys.argv[1:] = ["--score-only", "--output", "output", "--visualize"]
cli.main()
Expand All @@ -66,3 +140,4 @@ def test_visualize_score_only(root_path=ROOT_PATH):
source_length = len(f.readlines())
images = list(Path(visual_folder_path).glob("*.png"))
assert len(images) == source_length
shutil.rmtree("output")
3 changes: 2 additions & 1 deletion simuleval/utils/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ def make_graph(self):

##### 2nd PLOT #####
# Load the audio file data
audio_path = os.path.join(self.path, "../", data["source"][0])
example_path = Path(self.path).parent
audio_path = example_path / data["source"][0]
audio_data, rate = soundfile.read(audio_path)
length = audio_data.shape[0] / rate
time = np.linspace(0, length, audio_data.shape[0])
Expand Down

0 comments on commit dfc5490

Please sign in to comment.