Lyte commited on
Commit
4f029bd
·
verified ·
1 Parent(s): 3b2a4c8

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +83 -0
README.md CHANGED
@@ -24,3 +24,86 @@ configs:
24
  - split: test
25
  path: data/test-*
26
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  - split: test
25
  path: data/test-*
26
  ---
27
+
28
+ # How to Use the DarijaTTS-v0.2 Dataset
29
+
30
+ Code:
31
+ ```python
32
+ import IPython.display as ipd
33
+ import io
34
+ import numpy as np
35
+ import tempfile
36
+ import wave
37
+ import os
38
+
39
+ from datasets import load_dataset
40
+ from IPython.display import Audio
41
+
42
+ # Load the DarijaTTS-v0.2 dataset with streaming
43
+ streaming_dataset = load_dataset("Lyte/DarijaTTS-v0.2", streaming=True)
44
+
45
+ print("Dataset loaded with streaming:")
46
+ print(streaming_dataset)
47
+
48
+ # Function to play audio from a streaming dataset element
49
+ def play_streaming_audio(element, sampling_rate=22050):
50
+ """
51
+ Plays audio bytes from a streaming dataset element by processing the bytes and creating a temporary WAV file.
52
+
53
+ Args:
54
+ element: The dataset element containing the audio.
55
+ sampling_rate: The sampling rate to use for the audio playback.
56
+ """
57
+ audio_bytes = element['audio']['bytes']
58
+ temp_filename = None
59
+
60
+ try:
61
+ # Convert the bytes to a NumPy array, assuming float64 data based on previous success
62
+ audio_data = np.frombuffer(audio_bytes, dtype=np.float64)
63
+
64
+ # Convert float64 to int16 (standard for WAV) and scale
65
+ int16_data = np.int16(audio_data * 32767)
66
+
67
+ # Create a temporary WAV file
68
+ with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as temp_file:
69
+ temp_filename = temp_file.name
70
+
71
+ with wave.open(temp_filename, 'wb') as wf:
72
+ wf.setnchannels(1) # Mono
73
+ wf.setsampwidth(2) # 16-bit (2 bytes)
74
+ wf.setframerate(sampling_rate) # Sample rate
75
+ wf.writeframes(int16_data.tobytes())
76
+
77
+ # Play the temporary WAV file
78
+ display(Audio(temp_filename, rate=sampling_rate))
79
+
80
+ except Exception as e:
81
+ print(f"Error processing and playing audio: {e}")
82
+ print("Could not play audio.")
83
+ finally:
84
+ # Clean up the temporary file if it was created
85
+ if temp_filename and os.path.exists(temp_filename):
86
+ os.remove(temp_filename)
87
+
88
+ # Function to iterate through and play a number of streaming audio examples
89
+ def play_streaming_examples(dataset, num_examples_to_play=5, sampling_rate=22050):
90
+ """
91
+ Iterates through and plays a specified number of audio examples from a streaming dataset.
92
+
93
+ Args:
94
+ dataset: The loaded streaming dataset object.
95
+ num_examples_to_play: The number of examples to play.
96
+ sampling_rate: The sampling rate to use for the audio playback.
97
+ """
98
+ print(f"\nPlaying the first {num_examples_to_play} audio examples...")
99
+
100
+ for i, element in enumerate(dataset['train']):
101
+ if i >= num_examples_to_play:
102
+ break
103
+
104
+ print(f"\nPlaying example {i+1}")
105
+ play_streaming_audio(element, sampling_rate=sampling_rate)
106
+
107
+ # Example of how to use the play_streaming_examples function
108
+ play_streaming_examples(streaming_dataset, num_examples_to_play=3, sampling_rate=22050)
109
+ ```