R-Kentaren commited on
Commit
8ec5670
·
verified ·
1 Parent(s): 55acefc

Delete colab.ipynb

Browse files
Files changed (1) hide show
  1. colab.ipynb +0 -147
colab.ipynb DELETED
@@ -1,147 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "markdown",
5
- "metadata": {},
6
- "source": [
7
- "# Audio to Animalese Language Conversion (Colab)\n",
8
- "\n",
9
- "This Colab notebook lets you convert any audio file (spoken English, for example) into Animalese — the iconic gibberish speech from Animal Crossing games!\n",
10
- "\n",
11
- "## Features\n",
12
- "- Upload any audio file (wav/mp3/m4a, etc.)\n",
13
- "- Transcribe to text (using `openai-whisper` or `speech_recognition`)\n",
14
- "- Convert text to Animalese audio (using pitch-shifted, sped-up syllable samples)\n",
15
- "- Download the final Animalese audio\n",
16
- "\n",
17
- "---"
18
- ]
19
- },
20
- {
21
- "cell_type": "code",
22
- "metadata": {},
23
- "source": [
24
- "#@title 1. Install dependencies\n",
25
- "!pip install gTTS pydub librosa soundfile openai-whisper --quiet\n",
26
- "!apt-get install -y ffmpeg\n",
27
- "\n",
28
- "import os\n",
29
- "from gtts import gTTS\n",
30
- "from pydub import AudioSegment\n",
31
- "import librosa\n",
32
- "import soundfile as sf\n",
33
- "import tempfile\n",
34
- "import torch\n",
35
- "import whisper"
36
- ],
37
- "execution_count": null,
38
- "outputs": []
39
- },
40
- {
41
- "cell_type": "code",
42
- "metadata": {},
43
- "source": [
44
- "#@title 2. Upload your audio file\n",
45
- "from google.colab import files\n",
46
- "\n",
47
- "uploaded = files.upload()\n",
48
- "input_audio_path = list(uploaded.keys())[0]\n",
49
- "print('Audio uploaded:', input_audio_path)"
50
- ],
51
- "execution_count": null,
52
- "outputs": []
53
- },
54
- {
55
- "cell_type": "code",
56
- "metadata": {},
57
- "source": [
58
- "#@title 3. Transcribe audio to text (English)\n",
59
- "model = whisper.load_model('base')\n",
60
- "result = model.transcribe(input_audio_path)\n",
61
- "transcription = result['text']\n",
62
- "print('Transcription:', transcription)"
63
- ],
64
- "execution_count": null,
65
- "outputs": []
66
- },
67
- {
68
- "cell_type": "markdown",
69
- "metadata": {},
70
- "source": [
71
- "## Animalese Synthesizer Function\n",
72
- "This function splits text into syllables and plays a pitch-shifted, short 'beep' per syllable to mimic Animalese."
73
- ]
74
- },
75
- {
76
- "cell_type": "code",
77
- "metadata": {},
78
- "source": [
79
- "#@title 4. Animalese Synthesizer\n",
80
- "import numpy as np\n",
81
- "\n",
82
- "def text_to_animalese(text, out_path='animalese.wav', base_pitch=220, speed=1.3):\n",
83
- " # Generate a single \"beep\" (vowel-like tone)\n",
84
- " def beep(pitch=220, dur_ms=80):\n",
85
- " sr = 22050\n",
86
- " t = np.linspace(0, dur_ms/1000, int(sr * dur_ms/1000), False)\n",
87
- " tone = np.sin(pitch*2*np.pi*t)\n",
88
- " tone *= np.hanning(len(t)) # fade in/out\n",
89
- " return np.int16(tone * 32767)\n",
90
- " \n",
91
- " import re\n",
92
- " # Split text into syllables (very rough, English only)\n",
93
- " text = text.lower()\n",
94
- " syllables = re.findall(r'[aeiouy]+|[^aeiouy\\W]+', text)\n",
95
- " \n",
96
- " # Map each syllable to a pitch for variety\n",
97
- " vowels = 'aeiouy'\n",
98
- " audio = np.array([], dtype=np.int16)\n",
99
- " for i, syl in enumerate(syllables):\n",
100
- " if syl.strip() == '':\n",
101
- " continue\n",
102
- " # Pitch shifts for variety\n",
103
- " pitch = base_pitch + 40 * (i % 5)\n",
104
- " beep_snd = beep(pitch=pitch)\n",
105
- " audio = np.concatenate([audio, beep_snd])\n",
106
- " \n",
107
- " # Speed up\n",
108
- " audio_fast = librosa.effects.time_stretch(audio.astype(np.float32)/32768.0, speed)\n",
109
- " sf.write(out_path, audio_fast, 22050)\n",
110
- " print(f'Animalese audio saved to {out_path}')\n",
111
- "\n",
112
- "animalese_out = 'animalese.wav'\n",
113
- "text_to_animalese(transcription, animalese_out)"
114
- ],
115
- "execution_count": null,
116
- "outputs": []
117
- },
118
- {
119
- "cell_type": "code",
120
- "metadata": {},
121
- "source": [
122
- "#@title 5. Listen and Download Animalese Audio\n",
123
- "import IPython.display as ipd\n",
124
- "ipd.display(ipd.Audio(animalese_out))\n",
125
- "files.download(animalese_out)"
126
- ],
127
- "execution_count": null,
128
- "outputs": []
129
- }
130
- ],
131
- "metadata": {
132
- "colab": {
133
- "collapsed_sections": [],
134
- "name": "Audio to Animalese Colab"
135
- },
136
- "kernelspec": {
137
- "display_name": "Python 3",
138
- "language": "python",
139
- "name": "python3"
140
- },
141
- "language_info": {
142
- "name": "python"
143
- }
144
- },
145
- "nbformat": 4,
146
- "nbformat_minor": 0
147
- }