Last active
July 8, 2021 14:08
-
-
Save Nekodigi/92d76fb91620d3a5311f1818575445bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Singing Google" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"require gtts pydub" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from gtts import gTTS\n", | |
"from pydub import AudioSegment\n", | |
"from pydub.playback import play\n", | |
"\n", | |
"def speak(datas):\n", | |
" hipitch_sounds = AudioSegment.empty()\n", | |
" for i, data in enumerate(datas):\n", | |
" s = data[0]\n", | |
" note = data[1]\n", | |
" vel = data[2]\n", | |
" print(s, note)\n", | |
" tts = gTTS(s, lang='ja')\n", | |
" tts.save('temp.mp3')\n", | |
" sound = AudioSegment.from_file('temp.mp3', format=\"mp3\")\n", | |
" sound = sound.speedup(playback_speed=vel, crossfade=0)\n", | |
" new_sample_rate = int(sound.frame_rate * (2.0 ** (note/12)))\n", | |
" hipitch_sound = sound._spawn(sound.raw_data, overrides={'frame_rate': new_sample_rate})\n", | |
" hipitch_sound = hipitch_sound.set_frame_rate(44100)\n", | |
" hipitch_sound = hipitch_sound[30:700/vel]\n", | |
" hipitch_sounds += hipitch_sound\n", | |
" hipitch_sounds.export(\"speak.wav\", format=\"wav\")\n", | |
" play(hipitch_sounds)\n", | |
"# for i in range(len(datas)):\n", | |
"# play(hipitch_sounds[i])\n", | |
" " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"space = 'っっっっっっっっっっっっっっっっっっっっっっっっっっっっっっっっっっっっっっっっっっっっっっっっっっっ'" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"speak([['あー',3,2], ['あー', 1,2], ['あー', -1,2],['あー',-2,1.5],['あー',0,2]])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.8.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment