Creating transcription helper functions
1. Creating transcription helper functions
You've come a long way. From exploring an audio file from scratch to manipulating audio files to working with different transcription APIs. In this chapter, you're going to be putting everything you've learned together by building a proof of concept spoken language processing pipeline. Acme Studios, a technology company, has approached you to use your speech processing skills to gain insights on their customer support calls. They've sent you a handful of audio samples to explore and to see what you can find. They let you know they're not quite sure of the quality of the files or the format they're recorded in.2. Exploring audio files
You open the folder of audio files Acme have sent through using the os module's listdir function and notice they're in the mp3 format. You've seen this before but before continuing you decide to write down a list of things you're going to do to prepare for building the proof of concept.3. Preparing for the proof of concept
The first thing will be to listen to a few of the files using your media player or PyDub's play function to get an understanding of what you're working with, and then to transcribe one as soon as possible using recognize google so you have a baseline to work off. You convert the first file to wav and transcribe but you know from previous work, doing this for every file is tedious.4. Functions we'll create
You decide it's a good idea to create functions which will help you for the rest of the proof of concept. One to convert files to wav format, one to find stats of an audio file using PyDub and another to transcribe an audio file using recognize google.5. Creating a file format conversion function
The first one convert to wav takes a file pathname and converts the file to a wav file. You'll first import the file as an AudioSegment, then create a new file name for it using the split function on the filename and adding the dot wav string extension. Finally, you'll use the export function to export it to wav format with the new file name, similar to what you did in a previous lesson.6. Using the file format conversion function
Great, now you can convert audio files without repeating yourself. Now let's make one to find an audio files attributes using PyDub.7. Creating an attribute showing function
show pydub stats takes a filename of an audio file and imports it as an AudioSegment. It then prints a number of attributes such as number of channels, sample width, frame rate and more.8. Using the attribute showing function
Since you're working with customer support calls, this will help especially with files with different numbers of channels. If there are two channels, you might be able to split them and transcribe each speaker separately.9. Creating a transcribe function
Finally, since you could be transcribing many audio files, you create a function to transcribe an audio file. transcribe audio takes a file path of an audio file and creates a speech recognition recognizer instance. It transcribes the audio file using recognize google as you've done in a previous lesson and returns the transcribed text.10. Using the transcribe function
Testing out the function on one of the calls works as expected. It reads in an audio file and returns the transcribed text. Excellent. Setting up helper functions like this at the start of a project may seem time-consuming but they'll help save time in the long run.11. Let's practice!
With that said, it's time to build them! Once you've got these ready to go, you'll be able to use some of your natural language processing skills on the transcribed text.Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.